How to count values in a certain range in a Numpy array?

后端 未结 5 845
被撕碎了的回忆
被撕碎了的回忆 2020-12-02 12:27

I have a NumPy array of values. I want to count how many of these values are in a specific range say x<100 and x>25. I have read about the counter, but it seems to on

5条回答
  •  余生分开走
    2020-12-02 12:50

    I think @Sven Marnach answer is quite nice, because it operates in on the numpy array itself which will be fast and efficient (C implementation).

    I like to put the test into one condition like 25 < x < 100, so I would probably do it something like this:

    len([x for x in a.ravel() if 25 < x < 100])

提交回复
热议问题