Indexing a numpy array with a list of tuples

后端 未结 2 685
忘了有多久
忘了有多久 2020-12-02 16:59

Why can\'t I index an ndarray using a list of tuple indices like so?

idx = [(x1, y1), ... (xn, yn)]
X[idx]

Instead I have to do something u

2条回答
  •  没有蜡笔的小新
    2020-12-02 17:56

    Use tuple of numpy arrays which can be directly passed to matrix to get the elements

    Index = tuple(np.array(list(zip(*index_tuple))))
    new_array = list(prev_array[index])
    

提交回复
热议问题