numpy.ndarray.size() 方法 | Python
numpy.ndarray.size()
函数返回数组中元素的数量。它等于 np.prod(a.shape),即数组维度的乘积。
Syntax : numpy.ndarray.size(arr)
Parameters :
arr : [array_like] Input array.
Return : [int] The number of elements in the array.
代码#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