''numpy.int64'对象没有属性'count'-在python中绘制图形时出错

问题描述 投票:0回答:1

plans = plans[plans.long_term_contract == 0].count()
plans = plans[plans.long_term_contract == 0].count()

AttributeError Traceback(最近一次通话)在----> 1个计划=计划[plans.long_term_contract == 0] .count()AttributeError:“ numpy.int64”对象没有属性“ count”

我想显示图形,首先我要对值为0和1的值进行计数,然后再为两个变量显示图形。我得到这个错误。如何计算numpy数组中的值?

python numpy plot graph
1个回答
0
投票

您可以使用numpy.count_nonzero

例如假设您要获取给定数组3arr的数量:

arr = array([[1, 2, 7, 3],
             [3, 9, 0, 4]])
np.count_nonzero(arr==3)

输出将是:

2
© www.soinside.com 2019 - 2024. All rights reserved.