【发布时间】:2015-04-24 04:34:33
【问题描述】:
在 Python 中,我有一个 ndarray y
打印为array([0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1])
我试图计算这个数组中有多少0s 和多少1s。
但是当我输入y.count(0) 或y.count(1) 时,它会显示
numpy.ndarray对象没有属性count
我该怎么办?
【问题讨论】:
-
这种情况下,也可以简单的使用
numpy.count_nonzero。
标签: python numpy multidimensional-array count