The dtype attributes

The dtype class has many useful properties.

Example:
Getting information about the character code

import numpy as np

t = np.dtype('Float64')
t.char

#out
'd'

The type attribute correspond to the type of object of the array elements.

import numpy as np

t = np.dtype('Float64')
t.type

#out
numpy.float64

The str attribute gives a string representation of a data type.

import numpy as np

t = np.dtype('Float64')
t.str

#out
'<f8'

The character < represent endianness which is related to the way bytes are ordered in a 32 and 64 bit word (in our case from the least important to the most important).

The f represents the character code.

The 8 represent the number of bytes each array needs.

Leave a Reply