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

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

    You could use the enumerate function, excluding the indexes:

    [x for i, x in enumerate(a) if i not in [1, 2, 5] ]
    

    including them:

    [x for i, x in enumerate(a) if i in [1, 2, 5]]
    

提交回复
热议问题