I have a binary multidimensional 2D array let's say
import numpy as np
arr = np.array([
[False, False, True],
[True, False, False],
[True, True, False],
])
I need a row and column for each element Truein the matrix:
[(0, 2), (1, 0), (2, 0), (2, 1)]
I know I can do this through iteration:
links = []
nrows, ncols = arr.shape
for i in xrange(nrows):
for j in xrange(ncols):
if arr[i, j]:
links.append((i, j))
Is there a faster or more intuitive way?
source
share