计算Python中数组中元素的数量,无论它是什么尺寸 [英] Count the number of elements in array in Python whatever dimension it is

查看:283
本文介绍了计算Python中数组中元素的数量,无论它是什么尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想轻松地计算NumPy数组中元素的数量,但是我不知道它们的维数是先验的.是否有通用函数可以计算numpy数组中元素的数量,无论其尺寸是多少?

I want to count easily the number of elements in a NumPy array, but I don't know a priori their dimensions. Is there a generic function that counts the number of elements in a numpy array whatever its dimension is?

谢谢

推荐答案

numpy.ndarray.size 返回数组中的许多元素

numpy.ndarray.size returns a number of elements in the array

>>> x = np.zeros((3, 5, 2), dtype=np.complex128)
>>> x.size
30

这篇关于计算Python中数组中元素的数量,无论它是什么尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆