Oğuz Şerbetci
Oğuz Şerbetci

Reputation: 2067

How to index multidimensional numpy array with another numpy array

Let's assume I have following numpy arrays:

idx = [1,2]
A   = [[1,2,3],
       [4,5,6],
       [7,8,9]]

I want to get A[idx[0],idx[1]]

A[idx] gets a slice. And I don't want to use A[idx[0],idx[1]] for clarity reasons

Upvotes: 0

Views: 46

Answers (1)

Oğuz Şerbetci
Oğuz Şerbetci

Reputation: 2067

I have found a solution:

A[tuple(indx)]

Upvotes: 2

Related Questions