Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将整数数组转换为unicode_Python_Python 3.x_Python 2.7 - Fatal编程技术网

Python 将整数数组转换为unicode

Python 将整数数组转换为unicode,python,python-3.x,python-2.7,Python,Python 3.x,Python 2.7,我有一个数组arr=[07,10,11,05]。 实际上,我希望将这些值转换为十六进制并发送给函数。我知道我可以将值分别转换为十六进制,比如十六进制(arr[0])、十六进制(arr[1])等等。我现在所做的是将数组转换为 unicode作为arr=[u'07 0a 0b 05']手动,然后发送到为我服务的函数。但当我必须在arr中发送数百个unicode字符串时,这太不切实际了 arr = [u'a3 06 06 01 00 01 01 00', u'a3 06 06 02 00 01 02

我有一个数组arr=[07,10,11,05]。 实际上,我希望将这些值转换为十六进制并发送给函数。我知道我可以将值分别转换为十六进制,比如十六进制(arr[0])、十六进制(arr[1])等等。我现在所做的是将数组转换为 unicode作为arr=[u'07 0a 0b 05']手动,然后发送到为我服务的函数。但当我必须在arr中发送数百个unicode字符串时,这太不切实际了

arr = [u'a3 06 06 01 00 01 01 00',
u'a3 06 06 02 00 01 02 00',
u'a3 06 06 03 00 01 03 00',
u'a3 06 06 04 00 01 04 00',
u'a3 06 06 05 00 01 05 00',
u'a3 06 06 06 00 01 06 00',
u'a3 06 06 07 00 01 07 00']
我使用循环一个接一个地发送(arr[I])。有没有一种方法可以动态地将整数数组转换为unicode,并将其发送到一个外部函数,该函数可以随时接受这样的unicode字符串?

''。join(map(hex,arr))
您在找什么

更具体地说:

import numpy as np

a = np.array([[1,2,3],[6,11,23]])

def strip_hexstring(s):
    return s.strip('0x').strip('L')

def format_line(line):
    return u'{}'.format(' '.join(map(strip_hexstring,map(hex,line))))

arr = [format_line(a[i,:]) for i in range(a.shape[0])]
如有必要,您可以像示例中那样用零填充。

'.join(map(hex,arr))
您在寻找什么

更具体地说:

import numpy as np

a = np.array([[1,2,3],[6,11,23]])

def strip_hexstring(s):
    return s.strip('0x').strip('L')

def format_line(line):
    return u'{}'.format(' '.join(map(strip_hexstring,map(hex,line))))

arr = [format_line(a[i,:]) for i in range(a.shape[0])]

如有必要,您可以像示例中那样用零填充。

这就是您要寻找的吗?:
arr=[hex(i)表示arr中的i]
,或者
arr=[chr(i)表示arr中的i]
,或者如果
07
表示
g
,那么
arr=[chr(i+96)表示arr中的i
,或者如果
07
表示
h
arr=[chr+97)对于arr中的i来说,这就是你要寻找的吗?:
arr=[hex(i)for i in arr]
,或者
arr=[chr(i)for i in arr]
,或者如果
07
意味着
g
,那么
arr=[chr(i+96)for i in arr]
,或者如果
07
意味着
h
那么
arr=[chr(i+97)for i in arr