布尔数组的方法

作者: 庵下桃花仙 | 来源:发表于2019-01-30 12:10 被阅读8次

布尔数组会被强制为1和0。因此,sum可以用来统计True的个数。

In [106]: arr = np.random.randn(100)

In [107]: (arr > 0).sum()
Out[107]: 52

any、all,检查数组中至少一个True或都是True。

In [108]: bools = np.array([False, False,True,False])

In [109]: bools.any()
Out[109]: True

In [110]: bools.all()
Out[110]: False

相关文章

网友评论

    本文标题:布尔数组的方法

    本文链接:https://www.haomeiwen.com/subject/zogqsqtx.html