1
我正在使用scipy.ndimage.label
的大陣列(3000 x 3000)。返回是3403個標籤和標籤數組。我想知道這些標籤的索引。對於標籤1,我應該知道標籤數組中的行和列。 所以基本上是這樣的除了np以外,Scipy標籤陣列的索引計算更快。其中
a[0] = array([[1, 1, 0, 0],
[1, 1, 0, 2],
[0, 0, 0, 2],
[3, 3, 0, 0]])
indices = [np.where(a[0]==t+1) for t in range(a[1])] #where a[1] = 3 is number of labels.
print indices
[(array([0, 0, 1, 1]), array([0, 1, 0, 1])), (array([1, 2]), array([3, 3])), (array([3, 3]), array([0, 1]))]
而且我想創建索引的列表中的所有標籤3403像上面。上述方法似乎很慢。我嘗試過使用生成器,它看起來不像有改進。
有什麼有效的方法嗎?
向我們展示您的工作loopy解決方案。 – Divakar
@Divakar indices = [np.where(m [0] == t + 1)for range in(m [1])]其中m [0]是標記數組,m [1]是標記計數(3403這裏)。 – Gargantua89
請將這些添加到問題中。很高興看到示例數據。 – Divakar