Numpy: find index of the elements within range

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

    s=[52, 33, 70, 39, 57, 59, 7, 2, 46, 69, 11, 74, 58, 60, 63, 43, 75, 92, 65, 19, 1, 79, 22, 38, 26, 3, 66, 88, 9, 15, 28, 44, 67, 87, 21, 49, 85, 32, 89, 77, 47, 93, 35, 12, 73, 76, 50, 45, 5, 29, 97, 94, 95, 56, 48, 71, 54, 55, 51, 23, 84, 80, 62, 30, 13, 34]
    
    dic={}
    
    for i in range(0,len(s),10):
        dic[i,i+10]=list(filter(lambda x:((x>=i)&(x

    Output:

    (0, 10)
    [7, 2, 1, 3, 9, 5]
    (20, 30)
    [22, 26, 28, 21, 29, 23]
    (30, 40)
    [33, 39, 38, 32, 35, 30, 34]
    (10, 20)
    [11, 19, 15, 12, 13]
    (40, 50)
    [46, 43, 44, 49, 47, 45, 48]
    (60, 70)
    [69, 60, 63, 65, 66, 67, 62]
    (50, 60)
    [52, 57, 59, 58, 50, 56, 54, 55, 51]  
    

提交回复
热议问题