1
如果我有一個16字節的字符串,我怎樣才能將它轉換爲numpy中的2 uint64數組? (指定是小端還是大端)typecast字節到Python中的uint64數組+ numpy
如果我有一個16字節的字符串,我怎樣才能將它轉換爲numpy中的2 uint64數組? (指定是小端還是大端)typecast字節到Python中的uint64數組+ numpy
IIUC,您可以使用np.fromstring
:
>>> n = range(16)
>>> s = ''.join(map(chr, n))
>>> np.fromstring(s, dtype=np.uint64)
array([506097522914230528, 1084818905618843912], dtype=uint64)
>>> sum((256**i)*x for i,x in enumerate(n[:8]))
506097522914230528L
>>> sum((256**i)*x for i,x in enumerate(n[8:]))
1084818905618843912L
雖然你必須翻轉ENDIANNESS自己。雖然人們經常使用非常鬆散的演員陣容,但它更像是演員陣容。
啊,謝謝!這對我行得通。 –