find index of elements within a range

a = np.array([1, 3, 5, 6, 9, 10, 14, 15, 56])  
np.where(np.logical_and(a>=6, a<=10)) --> (array([3, 4, 5]),)
(a >= 6) & (a <=10) --> array([False, False, False,  True,  True,  True, False, False, False])
a[(a >= 6) & (a <=10)] = 100 --> array([  1,   3,   5, 100, 100, 100,  14,  15,  56])

参考:
[1] https://stackoverflow.com/questions/13869173/numpy-find-index-of-the-elements-within-range

posted @ 2023-04-11 13:01  xiaoxuxli  阅读(9)  评论(0编辑  收藏  举报