3

I have a numpy array which which has a shape of (10, 3) and looks like:

10 | xxx | yyy
11 | xxx | yyy
13 | xxx | yyy
14 | xxx | yyy
15 | xxx | yyy
17 | xxx | yyy
19 | xxx | yyy
..............

What I want is to extract only the rows which have the value of the first column between 12 and 16, for example. I tried with numpy.where(), but I didn't really manage to.

So what I want is something that returns:

13 | xxx | yyy
14 | xxx | yyy
15 | xxx | yyy

2 Answers 2

2

You can try something like this

b = your_array[:,0]
condition = (b>12) & (b<16)

new_array = your_array[condition]
Sign up to request clarification or add additional context in comments.

Comments

0

Using filter and lambda:

filtered_array = numpy.array(filter(lambda row: 12<row[0]<16, array))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.