NumPy: Finding dimension, data type, shape and size of ndarray

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:

  1. ndarray.ndim: It is used to represent the number of dimensions of the ndarray.
  2. ndarray.shape:It is tuple of integer indicating the number of elements that are stored along each dimension of array.
  3. ndarray.size:It is total number of elements present in Numpy array.
  4. ndarray.dtype: It tells the data type of the elements of a NumPy array.
  5. 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