0

Here is an example

>>>a = np.array([[1,2],[3,5]])
>>>a
array([[1, 2],
       [3, 5]])
>>>b = np.array([0, 1])

I am looking for a method to pick the 0th and 1st elements (depicted by array b) from the 0th and 1st row from array a as in:

>>>np.array([a[b[0]], a[b[1]]]) = np.array([1, 5])
user2165
  • 1,951
  • 3
  • 20
  • 39

1 Answers1

0

According to the so-called advanced indexing, this will do the job

a[[0,1],[0,1]]

user2165
  • 1,951
  • 3
  • 20
  • 39