Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.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长(16字节uuid)转换为numpy无符号int64数组?_Python_Numpy_Type Conversion_Long Integer_Uuid - Fatal编程技术网

如何将python长(16字节uuid)转换为numpy无符号int64数组?

如何将python长(16字节uuid)转换为numpy无符号int64数组?,python,numpy,type-conversion,long-integer,uuid,Python,Numpy,Type Conversion,Long Integer,Uuid,我试图找到在python中存储16字节(128位)长的int(uuid.uuid对象的int表示)的最佳方法,首先将其转换为numpy.ndarray(dtype=np.uint64,shape=(2,)对象 我知道python long的内部内存表示并不简单,所以我假设内存中没有16字节可以用来构造numpy.array 我目前的解决方案(Python2.7)是在长整数上使用手动移位,这是可行的,但决不是优雅和快速的 将numpy导入为np py_long=0x1234567890ABCDF8

我试图找到在python中存储16字节(128位)长的int(uuid.uuid对象的int表示)的最佳方法,首先将其转换为
numpy.ndarray(dtype=np.uint64,shape=(2,)
对象

我知道python long的内部内存表示并不简单,所以我假设内存中没有16字节可以用来构造
numpy.array

我目前的解决方案(Python2.7)是在长整数上使用手动移位,这是可行的,但决不是优雅和快速的

将numpy导入为np
py_long=0x1234567890ABCDF888888777777L
#从(16字节)长到int64数组
np_arr=np.array([py_long>>64,py_long&0xffffffffffff],dtype=np.uint64)
#从int64数组到(16字节)长

py_long=(long(np_arr[0]),如果您仍然有
uuid.uuid
实例:它有一个
bytes
和一个
bytes\u le
属性,其中16个字节以大尾和小尾的顺序排列。为什么会有明显的方式(移位和掩蔽)不优雅?如何在内部表示
int
是一个实现细节,因此当您只有
int
(在Python 2.7中)时,实际上没有其他选择。