📜  numpy.ndarray.size() 方法 | Python

📅  最后修改于: 2022-05-13 01:54:52.209000             🧑  作者: Mango

numpy.ndarray.size() 方法 | Python

numpy.ndarray.size()函数返回数组中元素的数量。它等于 np.prod(a.shape),即数组维度的乘积。

代码#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