Skip to main content

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.


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)


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
Submitted by devanshi.srivastava on August 3, 2021

Devanshi, is working as a Data Scientist with iVagus. She has expertise in Python, NumPy, Pandas and other data science technologies.


At ProgramsBuzz, you can learn, share and grow with millions of techie around the world from different domain like Data Science, Software Development, QA and Digital Marketing. You can ask doubt and get the answer for your queries from our experts.