What is the difference between dtype=\'f\'
, dtype=\'f4\'
, dtype=\'>f4\'
, dtype\'
Endian-ness.
<
= little-endian (LSB first)
>
= big-endian (MSB first)
https://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.byteorder.html
I just had the same question and tried to search the answer online.
'f' is the shorthand for 'float32'.
'f4' also means 'float32' because it has 4 bytes and each byte has 8 bits.
Similarly, 'f8' means 'float64' because 8*8 = 64.
For the difference between '>f4' and '<f4
', it is related to how the 32 bits are stored in 4 bytes.
('>')Big Endian Byte Order: The most significant byte (the "big end") of the data is placed at the byte with the lowest address. The rest of the data is placed in order in the next three bytes in memory.
('<')Little Endian Byte Order: The least significant byte (the "little end") of the data is placed at the byte with the lowest address. The rest of the data is placed in order in the next three bytes in memory.
Please see this link for more detailed information: https://chortle.ccsu.edu/AssemblyTutorial/Chapter-15/ass15_3.html
By looking up the data type object you can see that the '>' and '<' reference the Endianess of the datatype
https://docs.scipy.org/doc/numpy/reference/arrays.dtypes.html
>>> dt = np.dtype('>H') # big-endian unsigned short
>>> dt = np.dtype('<f') # little-endian single-precision float
f is a single-precision floating point number and in your case it uses 4 bytes (4 x 8 = 32 bits).
dtype='<f4'
Makes dtype a 32 bit single-precision floating point number using little endian order of bytes.
More on Endianness can be found using wiki https://en.wikipedia.org/wiki/Endianness