These days, I've switched from Matlab to NumPy/SciPy.
Today, I encountered a weird problem when I tried to load data stored in "binary format". Audio data is stored in the 4-byte single-precision floating point number format. I tried the following first.
data = np.fromfile('out.raw', dtype=float) # This is wrong
plt.plot(data)
But it didn't work. After some search, I tried the following, and it worked as expected:
data = np.fromfile('out.raw', dtype=np.float32) # This is okay.
plt.plot(data)
Based on my previous experience with C/C++, I had expected "float" to be a 4-byte single-precision floating point type. But it turns out that the float is 8-byte data, and in the above case, I should have used np.float32.
I have two questions regarding this.
Q1. Why is the float 8-byte rather than 4-byte, which might be confusing to C/C++ programmers?
Q2. Why can't I use dtype=float32. This causes an error to me. I seems like I should use dtype=np.float32?
Thank you!