Data type Object
Data type Object
Every ndarray has an associated data type (dtype) object. This data type object (dtype) informs us
about the layout of the array. This means it gives us information about:
If the data type is a sub-array, what is its shape and data type?
The values of a ndarray are stored in a buffer which can be thought of as a contiguous block of
memory bytes. So how these bytes will be interpreted is given by the dtype object.
1. Constructing a data type (dtype) object: A data type object is an instance of the NumPy.dtype
class and it can be created using NumPy.dtype.
Parameters:
Python
import numpy as np
print(x[1])
print("Grades of John are: ",x[1]['grades'])
Output:
int16
Python
Output:
Size is: 4
The type specifier (i4 in the above case) can take different forms:
b1, i1, i2, i4, i8, u1, u2, u4, u8, f2, f4, f8, c8, c16, a
(representing bytes, ints, unsigned ints, floats, complex and
fixed-length strings of specified byte lengths)
Note:
Python
import numpy as np
a = np.array([1])
Output:
type is:
Python
import numpy as np
print(dt['grades'])
print(dt['name'])
Output:
('<f8', (2,))
Python
import numpy as np
print(x[1])
Output: