【发布时间】:2014-08-07 07:41:18
【问题描述】:
我有一个矩阵,我想写一个脚本来提取大于零的值,它的行号和列号(因为值属于那个(行,列)),这是一个例子,
from numpy import *
import numpy as np
m=np.array([[0,2,4],[4,0,4],[5,4,0]])
index_row=[]
index_col=[]
dist=[]
我想将行号存储在 index_row 中,列号存储在 index_col 中,并将值存储在 dist 中。所以在这种情况下,
index_row = [0 0 1 1 2 2]
index_col = [1 2 0 2 0 1]
dist = [2 4 4 4 5 4]
如何添加代码来实现这个目标?谢谢你给我建议。
【问题讨论】:
标签: python arrays numpy indexing