3

Having arrays a, and b I would like to get the array c which excludes a from b.

a=np.array([8,14])

[ 8 14]

b=np.array([[3,2],[8,10],[8,14],[17,65]])

[[ 3  2]
 [ 8 10]
 [ 8 14]
 [17 65]]

The desired c is :

print(c)
[[ 3  2]
 [ 8 10]
 [17 65]]

numpy delete does not seem to work as expected because it takes the index as input for removing the section of array.

np.delete(b, a)
[ 3  2  8 10 8 14 17 65]

1 Answer 1

1

try this:

c = b[np.any(b != a, axis=(1))]
print(c)
Sign up to request clarification or add additional context in comments.

2 Comments

had to edit the question to better reflect the use case. We don't want to remove all elements of a from b, but just the specific arrays. Please see the edited question.
@MaryaPardi check my new solution

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.