How to select inverse of indexes of a numpy array?

前端 未结 4 1061
夕颜
夕颜 2020-12-07 00:19

I have a large set of data in which I need to compare the distances of a set of samples from this array with all the other elements of the array. Below is a very simple exa

4条回答
  •  没有蜡笔的小新
    2020-12-07 01:04

    I'm not familiar with the specifics on numpy, but here's a general solution. Suppose you have the following list:
    a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].
    You create another list of indices you don't want:
    inds = [1, 3, 6].
    Now simply do this:
    good_data = [x for x in a if x not in inds], resulting in good_data = [0, 2, 4, 5, 7, 8, 9].

提交回复
热议问题