numpy.ndarray.ndim() method | Python

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

Syntax : numpy.ndarray.ndim(arr)

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 :



filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :

1

 
Code #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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)

chevron_right


Output :

2
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.