numpy.ndarray.ndim() 方法 | Python
numpy.ndarray.ndim()
函数返回数组的维数。
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.
代码#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)
输出 :
1
代码#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)
输出 :
2