小编can*_*bag的帖子

Python/numpy:数组中的所有值都是x?

我有一个这样的有序数组: numpy.array([1, 2, 5, 10, 25, 36, 66, 90, 121, 230, 333, 500])

假设我希望所有值都达到60(如果60不在,我想停在第一个值大于60),所以我想要[1, 2, 5, 10, 25, 36, 66].如果我使用numpy.where()<= 60,它会在66之前停止.

我的解决方案

from numpy import *
x = array([1, 2, 5, 10, 25, 36, 66, 90, 121, 230, 333, 500])
print x[:where(x >= 60)[0][0]+1]
>>>[ 1  2  5 10 25 36 66]
Run Code Online (Sandbox Code Playgroud)

python arrays numpy

3
推荐指数
1
解决办法
1096
查看次数

标签 统计

arrays ×1

numpy ×1

python ×1