Say I have a Python script which reads some binary data, packed as int16. I want to convert this data to float32 as fast as possible.
Currently I am doing this, per file
data = np.fromfile(fid, 'int16').astype('float32')
This has the unfortunate effect that the fromfile and the astype take equally long (several seconds in my case). I was wondering if there's a faster way of doing this?
Maybe initializing a zero array and using np.frombuffer to finally populate two bytes at a time?
Please advise, thanks.