0

I have 2 numpy arrays of images,

X.shape =(76,224,224,3)
X_1.shape =(15,224,224,3)

The 15 images in X_1 are also in X. How can I get Z = X \ X_1? where Z may have shape=(61,224,224,3).

Thanks to all.

2
  • what exactly do you mean by intersection here? Full context match? Commented Nov 14, 2019 at 21:01
  • I mean that X_1 is contained in X, so i want to get the rest images that are in X and not in X_1. Commented Nov 14, 2019 at 21:14

1 Answer 1

1

The 15 images in X_1 are in X.

Doesn't that mean X∩X_1=X_1 since entire X_1 contained in X, so you just want Z = X-X_1?

I think you should look into numpy.delete


This is probably (definitely) not the fastest or the best way, but I got it to work by looking at this answer,

>>> X = np.random.randint(255, size=(76,224,224,3))
>>> X_1 = X[:15]
>>> X.shape
(76, 224, 224, 3)
>>> X_1.shape
(15, 224, 224, 3)
>>> ind_to_del = np.unique((X[:, None] == X_1).all(-1).argmax(0))
>>> ind_to_del
array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14])
>>> Z = np.delete(X, ind_to_del, axis=0)
>>> Z.shape
(61, 224, 224, 3)

So you want,

ind_to_del = np.unique((X[:, None] == X_1).all(-1).argmax(0))
Z = np.delete(X, ind_to_del, axis=0)
Sign up to request clarification or add additional context in comments.

3 Comments

This isn't what I want. Yes, I want to do X-X_1 but when I do it throws this error. operands could not be broadcast together with shapes (76,224,224,3) (15,224,224,3)
What is X \ X_1? Its the same as X / X_1?
Okay i got you, You mean the compliment. With numpy i cant do it with both sets because: this is the method: docs.scipy.org/doc/numpy/reference/generated/… and only accept 1d arrays.

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.