Python numpy.ndarray.ndim()
numpy.ndarray.ndim()函数返回一个数组的维数。
语法: numpy.ndarray.ndim(arr)
参数 :
arr : [array_like] 输入数组。如果它还不是一个ndarray,就会尝试进行转换。
返回 : [int] 返回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