I have a file reader that reads n bytes from a file and returns a string of chars representing that (binary) data. I want to read up n bytes into a numpy array of numbers and run a FFT on it, but I’m having trouble creating an array from a string. A couple lines of example would be awesome.
Edit:
I’m reading raw binary data, and so the string I get looks like '\x01\x05\x03\xff'.... I want this to become [1, 5, 3, 255].
In Python 2, you can do this directly with
numpy.fromstring:Once completing this,
aisarray([ 1, 5, 3, 255])and you can use the regular scipy/numpy FFT routines.In Python 3, the switch to default Unicode strings means that you would read in the data as a bytestring and use the
frombuffercommand instead:to get the same results.