Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

numpy.ndarray.ndim() method | Python

  • Last Updated : 26 Mar, 2020

numpy.ndarray.ndim() function return the number of dimensions of an array.

Syntax : numpy.ndarray.ndim(arr)

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

Parameters :
arr : [array_like] Input array. If it is not already an ndarray, a conversion is attempted.



Return : [int] Return the number of dimensions in arr.

Code #1 :




# Python program explaining
# numpy.ndarray.ndim() function
  
# importing numpy as geek 
import numpy as geek
  
arr = geek.array([1, 2, 3, 4])
  
gfg = arr.ndim
  
print (gfg)

Output :

1

 
Code #2 :




# Python program explaining
# numpy.ndarray.ndim() function
  
# importing numpy as geek 
import numpy as geek
  
arr = [[1, 2, 3], [4, 5, 6]]
  
gfg = geek.ndim(arr)
  
print (gfg)

Output :

2
My Personal Notes arrow_drop_up
Recommended Articles
Page :