DarthLazar DarthLazar - 3 months ago 10
Python Question

Python - Retrieving certain indicies from an array

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

x


I'm looking at numbers greater than 1.0,

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


returning

[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
x
?

I've tried each individually, but an error occurs

list(x).index(1.2958354)

ValueError: 1.2958354 is not in list

Answer

You can use enumerate function, for example:

mask1 =  [(i, value) for i, value in enumerate(x) if value>1.0 ]
print mask1
Comments