I need to figure out how I can find the whole index of a value in a 2d numpy array.
For example, I have the following 2d array:
([[1 1 0 0], [0 0 1 1], [0 0 0 0]])
I need to find the index of all 1 and 0.
1: [(0, 0), (0, 1), (1, 2), (1, 3)] 0: [(0, 2), (0, 3), (1, 0), (1, 1), (the entire all row)]
I tried this, but it does not give me all the indices:
t = [(index, row.index(1)) for index, row in enumerate(x) if 1 in row]
Basically, this gives me only one of the indices in each row [(0, 0), (1, 2)] .
python arrays numpy multidimensional-array
Pete
source share