In Numpy, Array Attributes are used to access an array through its attributes to get information that is intrinsic to the array itself.
These are some important attributes of NumPy Array:
- ndarray.ndim: It is used to represent the number of dimensions of the ndarray.
- ndarray.shape:It is tuple of integer indicating the number of elements that are stored along each dimension of array.
- ndarray.size:It is total number of elements present in Numpy array.
- ndarray.dtype: It tells the data type of the elements of a NumPy array.
- ndarray.itemsize: It gives the size in bytes of each element of a NumPy array.
Example:
import numpy as np
a = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]])
print("Dimension of the given Ndarray=",a.ndim)
print("Shape of the given Ndarray=",a.shape)
print("Size of the given Ndarray=",a.size)
print("Data Type of given Ndarray=",a.dtype)
print("Size of each element in Ndarray=",a.itemsize)
Output:
Dimension of the given Ndarray= 3 Shape of the given Ndarray= (2, 2, 3) Size of the given Ndarray= 12 Data Type of given Ndarray= int64 Size of each element in Ndarray= 8