2

My friend A is back and she now looks like

A = np.array([
    [0,1,1,1,0,0,0,0], 
    [1,0,0,1,0,0,0,0],
    [1,0,0,1,0,0,0,0],
    [1,1,1,0,0,0,0,0],
    [0,0,0,1,0,1,0,0],
    [0,0,0,0,1,0,1,1],
    [0,0,0,0,0,1,0,1],
    [0,0,0,0,0,1,1,0],
             ])

I need to find the sub-matrix that is H = A[(1,3,7), (2,3,6)]. But thats returns

array([0, 0, 1])

I'm expecting rows 1, 3 and 7 paired with columns 2,3 and 6. I can't seem to find that syntax.

H = [[0,1,0],
     [1,0,0],
     [0,0,1]]
Brian Dolan
  • 3,086
  • 2
  • 24
  • 35

1 Answers1

2

You can use np.ix_:

A[np.ix_((1,3,7),(2,3,6))]
#array([[0, 1, 0],
#       [1, 0, 0],
#       [0, 0, 1]])
Psidom
  • 209,562
  • 33
  • 339
  • 356