Extract elements from numpy array, that are not in list of indexes

前端 未结 4 2191
梦谈多话
梦谈多话 2020-12-06 19:38

I want to do something similar to what was asked here NumPy array, change the values that are NOT in a list of indices, but not quite the same.

Consider a nump

4条回答
  •  遥遥无期
    2020-12-06 19:56

    One way is to use a boolean mask and just invert the indices to be false:

    mask = np.ones(a.size, dtype=bool)
    mask[indxs] = False
    a[mask]
    

提交回复
热议问题