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

前端 未结 4 2194
梦谈多话
梦谈多话 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:43

    One approach with np.in1d to create the mask of the ones from indxs present and then inverting it and indexing the input array with it for the desired output -

    a[~np.in1d(np.arange(a.size),indxs)]
    

提交回复
热议问题