DarthLazar DarthLazar - 1 year ago 84
Python Question

Python - Retrieving certain indicies from an array

I have an array of numbers with shape (1220,) called


I'm looking at numbers greater than 1.0,

mask1 = [i for i in x if i>1.0 ]


[1.2958354, 1.0839227, 1.1919032]

My question now is then how am able to determine the index location of these values in my initial array

I've tried each individually, but an error occurs


ValueError: 1.2958354 is not in list

Answer Source

You can use enumerate function, for example:

mask1 =  [(i, value) for i, value in enumerate(x) if value>1.0 ]
print mask1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download