There are two general ways of indexing into a numpy array:
- Basic indexing and slicing which extends python's concept of slicing.
- Advanced Indexing where we generally use another ndarray containing integers/booleans.
You can read about these in the numpy documentation.
To answer your question: we can make use of advanced indexing here. The documentation contains an example, adapted below, which is already quite close to what we want:
>>> import numpy as np
>>> A = np.array([[1,2],
[3,4]])
>>> row_indices = np.array([[0,0],
[1,1]])
>>> col_indices = np.array([[1,0],
[1,0]])
>>> A[row_indices,col_indices]
array([[2, 1],
[4, 3]])
In the code in the question, Ord already contains the column indices, so all we need to do is generate the row indices ourselves. While this is probably not the best way to do this, here is one possible solution:
>>> A = np.array( [[0,1,2],
... [3,4,5],
... [6,7,8]])
>>> col_indices = np.array([[1,0,2],
... [0,2,1],
... [2,1,0]])
>>> row_indices = np.repeat([0,1,2],3).reshape(3,3)
>>> row_indices
array([[0, 0, 0],
[1, 1, 1],
[2, 2, 2]])
>>> A[row_indices, col_indices]
array([[1, 0, 2],
[3, 5, 4],
[8, 7, 6]])