Numpy: find index of the elements within range

前端 未结 12 2286
盖世英雄少女心
盖世英雄少女心 2020-11-28 23:01

I have a numpy array of numbers, for example,

a = np.array([1, 3, 5, 6, 9, 10, 14, 15, 56])  

I would like to find all the indexes of the

12条回答
  •  醉话见心
    2020-11-28 23:02

    Other way is with:

    np.vectorize(lambda x: 6 <= x <= 10)(a)
    

    which returns:

    array([False, False, False,  True,  True,  True, False, False, False])
    

    It is sometimes useful for masking time series, vectors, etc.

提交回复
热议问题