Easy way to test if each element in an numpy array lies between two values?

前端 未结 3 759
名媛妹妹
名媛妹妹 2020-12-02 13:02

I was wondering if there was a syntactically simple way of checking if each element in a numpy array lies between two numbers.

In other words, just as numpy.ar

3条回答
  •  爱一瞬间的悲伤
    2020-12-02 13:53

    Another would be to use numpy.any, Here is an example

    import numpy as np
    a = np.array([1,2,3,4,5])
    np.any((a < 1)|(a > 5 ))
    

提交回复
热议问题