What does datatype "S7" mean

Question:

Use the following command, the s.dtype will be ‘S7’, what does ‘S7’ means?

I have Googled, but only a Japanese website with failed link

I have read the Document in numpy, no luck

>>> strings = np.array([b'cat', b'dog', b'chicken', b'horse', b'goat'])
>>> s = strings[[0,1]]
>>> s.dtype
dtype('S7')

Thanks for your help

Asked By: Ryan Chen

||

Answers:

The dtype object describes how the bytes in the fixed-size block of memory corresponding to an array item should be interpreted. It describes different aspects of the data such as:

  • Type of data
  • Size of the data
  • Byte order of the data etc.

Here, ‘S7’ means that the object is of type string and it’s size(no. of bytes) is 7. You can confirm this by calling the ‘itemsize’ attribute for s.

>>>s.itemsize
7
Answered By: Aditya Keshri
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.