1

I have a multidimensional numpy array and I only want specific values in each column of the array. If the vlaue does not match that of what I am filtering by I want to delete the entire row. Code snippet:

array = ([4, 78.01, 65.00, 98.00],
         [5, 23.08, 87.68, 65.3],
         [6, 45.98, 56.54, 98.76],
         [7, 98.23, 26.65, 46.56])

For example column 1 I would like numbers between 0-90 and column 4 I would want values between 70-100. So my ideal output would be:

 array = ([4, 78.01, 65.00, 98.00],
         [6, 45.98, 56.54, 98.76])

Is there any way to do this?

1 Answer 1

2

You need to chain all conditions with bitwise operators and the perform boolean indexing:

array[(array[:,0] > 0) & (array[:,0] < 100) & (array[:,3] > 90) & (array[:,3] < 100)]

array([[ 4.  , 78.01, 65.  , 98.  ],
       [ 6.  , 45.98, 56.54, 98.76]])
Sign up to request clarification or add additional context in comments.

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.