Numpy: find index of the elements within range

前端 未结 12 2244
盖世英雄少女心
盖世英雄少女心 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:16

    You can use np.where to get indices and np.logical_and to set two conditions:

    import numpy as np
    a = np.array([1, 3, 5, 6, 9, 10, 14, 15, 56])
    
    np.where(np.logical_and(a>=6, a<=10))
    # returns (array([3, 4, 5]),)
    

提交回复
热议问题