Numpy extract row, column and value from a matrix
问题 I have a matrix, and I want to write a script to extract values which are bigger than zero, its row number and column number(because the value belongs to that (row, column)), and here's an example, from numpy import * import numpy as np m=np.array([[0,2,4],[4,0,4],[5,4,0]]) index_row=[] index_col=[] dist=[] I want to store the row number in index_row , the column number in index_col , and the value in dist . So in this case, index_row = [0 0 1 1 2 2] index_col = [1 2 0 2 0 1] dist = [2 4 4 4