Friday, April 3, 2026
HomeLanguagesnumpy.ndarray.ndim() method | Python

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 :




# 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
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32512 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6885 POSTS0 COMMENTS
Nicole Veronica
12006 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12100 POSTS0 COMMENTS
Shaida Kate Naidoo
7015 POSTS0 COMMENTS
Ted Musemwa
7259 POSTS0 COMMENTS
Thapelo Manthata
6971 POSTS0 COMMENTS
Umr Jansen
6960 POSTS0 COMMENTS