0

I have a numpy array as of right now that looks something like:

A =  [  [5, 8, 6, 2], 
        [5, 8, 6, 2], 
        [...], ...       ]

Let's say I have another 1D numpy array, that looks something like array B, but has at values that correspond to each of the lists inside A.

B = [0.4, 0.6, 0.3, ...]

Now I want to delete any list within the list that has a corresponding value within B that is greater than 0.5 (this could be represented by a variable named thresh). The resulting array should look like (since the second list had a greater value):

C =  [  [5, 8, 6, 2], 
        [...], ...       ]

I am looking for a good numpy based/ pythonic way of achieving this. I am aware of np.delete, but do not understand how to use it here with a condition.

1 Answer 1

1

How about condition Boolean slice

A[B<0.5]
Out[197]: 
array([[5, 8, 6, 2],
       [1, 1, 1, 1]])
Sign up to request clarification or add additional context in comments.

3 Comments

Cool solution! But is there a numpy way of doing this?
I tried A[B<thresh] and I got boolean index did not match indexed array along dimension 0;
@SharanDuggirala is A and B have same len ? , print len(A) and len(B)

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.