What do the << icons mean in numpy dtype?

What is the difference between dtype='f' , dtype='f4' , dtype='>f4' , dtype'<f4' ? The syntax is not explained in docs on types (except that 'f' is a shorthand for 'float32'); it is widely used on the records page, but the value > / < also remains inexplicable there.

After some experimentation, I found out that

  In [13]: a = np.array([1.0], dtype='f') In [15]: print(a.dtype) float32 

and

  In [16]: a = np.array([1.0], dtype='<f4') In [17]: print(a.dtype) float32 

but

  In [18]: a = np.array([1.0], dtype='>f4') In [19]: print(a.dtype) >f4 

This makes me think that they are not equivalent, which may be an explanation of the problems that the external library is encountering.

+5
source share
2 answers

Endian.

< = little-endian (LSB first)

> = big-endian (first MSB)

https://docs.scipy.org/doc/numpy/reference/generated/numpy.dtype.byteorder.html

+6
source

When searching for an object of a data type, you can see that '>' and '<' refer to Endianess of that data type

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 the minimum byte ordinal.

More about Endianness can be found using the wiki https://en.wikipedia.org/wiki/Endianness

+4
source

Source: https://habr.com/ru/post/1259722/


All Articles