I am trying to access specific rows and columns of a NumPy array as the documentation explains but I think I am missing something.
I have the following array:
arr = np.random.randint(10, size=(6, 4))
array([[1, 9, 6, 4],
[8, 5, 0, 3],
[3, 7, 3, 2],
[1, 4, 8, 0],
[5, 5, 8, 0],
[0, 6, 4, 9]])
And I want to get the first and last row; and the first, third and last column, so I am trying:
arr[(0, -1),(0, 1, 3)]
But this is producing the following error:
IndexError: shape mismatch: indexing arrays could not be broadcast together with shapes (2,) (3,)
I think I am misunderstanding this type of integer indexing. I would expect this output:
array([[1, 9, 4],
[0, 6, 9]])
I can do it this way but it feels really awkward:
arr[(0,-1),:][:,(0,1,3)]
How can I get the i-th elements of different dimensions?