I have this matrix; let’s say there are hundreds of x value and thousands of y lists inside this matrix:
[[100 0 0 ... 0 0 0]
[ 0 100 0 ... 0 0 0]
[ 0 0 100 ... 0 0 0]
...
[ 0 0 0 ... 100 0 0]
[ 0 0 0 ... 0 100 0]
[ 0 0 0 ... 0 0 100]]
How will I be able to retrieve the index of value >= 90 and put it in a nested list?
Here is the sample output:
[[0], [1, 167], [2, 498, 2890] ... [6568, 99998], [7894, 19695, 99999], [873, 100000]]
>Solution :
Try using nested list comprehension:
[[idx for idx, value in enumerate(row) if value >= 90] for row in arr]
To have the result of @azro’s, I’d rather use:
np.argwhere(arr >= 90)