[Numpy-discussion] converting list of int16 values to bitmask and back to bitmask and back to list of int32\float values

Nissim Derdiger NissimD at elspec-ltd.com
Sun Oct 8 03:12:56 EDT 2017

Hi again,
I realize that my question was not clear enough, so I've refined it into one runnable function (attached below)
My question is basically - is there a way to perform the same operation, but faster using NumPy (or even just by using Python better..)
Thanks again and sorry for the unclearness..

import struct

def Convert():
    Endian = '<I' # Big endian
    ParameterFormat = 'f' # float32
    RawDataList = [17252, 26334, 16141, 58057,17252, 15478, 16144, 43257] # list of int32 registers
    NumOfParametersInRawData = int(len(RawDataList)/2)
    Result = []
    for i in range(NumOfParametersInRawData):
        # pack every 2 registers, take only the first 2 bytes from each one, change their endianess than unpack them back to the Parameter format
        Result.append((struct.unpack(ParameterFormat,(struct.pack(Endian,RawDataList[(i*2)+1])[0:2] + struct.pack('<I',RawDataList[i*2])[0:2])))[0])

More information about the NumPy-Discussion mailing list