Assume I have the string:
my_data = '\x00\x00\x80?\x00\x00\x00@\x00\x00@@\x00\x00\x80@'
Where I got it is irrelevant, but for the sake of having something concrete, assume I read it from a binary file.
I know my string is the binary representation of 4 (4-byte) floats. I would like to get those floats as a numpy array. I could do:
import struct
import numpy as np
tple = struct.unpack( '4f', my_data )
my_array = np.array( tple, dtype=np.float32 )
But it seems silly to create an intermediate tuple. Is there a way to do this operation without creating an intermediate tuple?
EDIT
I would also like to be able to construct the array in such a way that I can specify the endianness of the string.