I have a two dimensional list in python with some floating point values. I want to find out indices of all the elements in the list which are above a specific value.
For example, in a 2 x 4 list as below (integer for convenience):
100 200 100 250
125 100 250 100
I need the indices of all the values which are equal or above 200. These indices are [0][1], [0][3] and [1][2].
Please help in this regards.
Thank you.
解决方案
Numpy is quite handy for this:
>>> import numpy as np
>>> a = [[100, 200, 100, 250], [125, 100, 250, 100]]
>>> a=np.array(a)
>>> np.argwhere(a>=200)
array([[0, 1],
[0, 3],
[1, 2]])