Eyal
Eyal

Reputation: 1

Get Specific Indices from a Grid in numpy

I run the following code:

    import numpy as np
    Z = np.arange(9).reshape(3,3)
    print(Z[[0,1],[0,2]])

Z is:

0 1 2
3 4 5
6 7 8

I expected to get the values 1 and 2 but got 0 and 5, so I don't understand how this indexing works.

Thanks

Upvotes: 0

Views: 153

Answers (1)

Ludovic H
Ludovic H

Reputation: 56

Z[[0,1],[0,2]] returns Z[0,0] and Z[1,2], that's why you get 0 and 5.

Upvotes: 1

Related Questions