1

Say I create the following numpy arrays of strings:

>>> np.array(['1.12', '-9.2', '42'], dtype=np.string_)
array([b'1.12', b'-9.2', b'42'], dtype='|S4')
>>> np.array(['1.12', '-9.2', '42'])
array(['1.12', '-9.2', '42'], dtype='<U4')

What do the types '|S4' and '<U4' mean? What is the size of a character with each?

planetp
  • 14,248
  • 20
  • 86
  • 160
  • And about [pipe sign here](https://stackoverflow.com/questions/14790130/dtypes-difference-between-s1-and-s2-in-python) – P. Dmitry Oct 11 '19 at 14:43
  • those are short names for data types, you get more detail in following link https://numpy.org/devdocs/reference/arrays.dtypes.html – Dev Khadka Oct 11 '19 at 14:47

1 Answers1

1

These are byte order flags. < is a "little endian" and | is "not applicable"

The < means:

When storing a multi-byte value in memory as a sequence of bytes, the sequence addresses/sends/stores the least significant byte first (lowest address) and the most significant byte last (highest address). Common in x86 processors.

Mason Caiby
  • 1,846
  • 6
  • 17
  • How am I supposed to use that information (endianness) ? – planetp Oct 11 '19 at 18:05
  • ('>')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. – Mason Caiby Oct 11 '19 at 20:35