Python numpy.ndarray.size()
numpy.ndarray.size()函数返回数组中的元素数。它等于np.prod(a.shape),即数组的尺寸之积。
语法: numpy.ndarray.size(arr)
参数 :
arr : [array_like] 输入阵列。
返回 : [int] 数组中的元素数量。
代码#1:
# Python program explaining
# numpy.ndarray.size() function
# importing numpy as geek
import numpy as geek
arr = geek.zeros((3, 4, 2), dtype = geek.complex128)
gfg = arr.size
print (gfg)
输出 :
24
代码#2:
# Python program explaining
# numpy.ndarray.size() function
# importing numpy as geek
import numpy as geek
arr = geek.zeros((3, 4, 2), dtype = geek.complex128)
gfg = geek.prod(arr.shape)
print (gfg)
输出 :
24