0

I am very new to Python, but I have experience with Matlab.

In my code I want to subscript 2D array using two 1D arrays as follows:

a=np.array([[1,2,3],[4,5,6],[7,8,9]])
patch=np.arange(2)
b = a [patch]
c= a[patch] [patch]

As a result, I want to have a 2x2 matrix: [(1, 2) (4, 5)]. Instead, my b and c are 2x3 matrices: b=c=[(1, 2, 3), (4,5,6)]

I was not able to solve it by myself. I know, that a[0:2,0:2] works, but in my code, I want to do it using predefined 1D arrays.

Thanks

Mikhail Genkin
  • 3,247
  • 4
  • 27
  • 47

0 Answers0