Skip to content Skip to sidebar Skip to footer

Convert Float Numpy Array To Big Endian

I wrote a script and in the end I need to convert this array which is in type float64 to big endian int (>2i): [[ 0.92702157 1.03092008 0.9072934 ..., 0.71617331 1.02524888

Solution 1:

>>> import numpy as np
>>> big_end = bytes(chr(0) + chr(1) + chr(3) + chr(2), 'utf-8')
>>> np.ndarray(shape=(2,),dtype='>i2', buffer=big_end)
array([  1, 770], dtype=int16)

see also: Byte-swapping


Post a Comment for "Convert Float Numpy Array To Big Endian"