I can get the index of non-zero numpy arrays as follows:
a = np.array([0., 1., 0., 2.])
i = np.nonzero(a)
This returns (array([1, 3]),). I can get the corresponding values as:
v = a[i]
Now what I would like to do is create a list with each of the (index, value) tuples. I guess one way to do so is to write a for loop as follows;
l = list()
for x in range(0, len(v)):
l.append((i[0][x], v[x]))
However, I was wondering if there is a better way to do this without writing the loop.
indexinindex[0][x]?