[Solved] How to extract out a non-continuous matrix from a larger matrix based on a list [closed]


You can do it by:

a =[
  [0,1,0,0,0,1],  
  [4,1,0,3,2,0],  
  [0,0,1,0,0,0],  
  [0,1,0,0,1,0],  
  [0,0,0,0,1,0],  
  [0,0,0,0,0,0],  
]
 
b = [0, 1, 3]
c = [[a[i][j] for j in b] for i in b]
print(c)
# ===>
# [[0, 1, 0], [4, 1, 3], [0, 1, 0]]

(Anyway, Python2 is no longer supported: link. I recommend you use Python3+NumPy, which supports various matrix operations such as flexible indexing that you want.)

0

solved How to extract out a non-continuous matrix from a larger matrix based on a list [closed]