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.

scribe
  • 673
  • 2
  • 6
  • 17

1 Answers1

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)
scribe
  • 673
  • 2
  • 6
  • 17
  • 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) – Jesus moyano Nov 14 '19 at 21:17
  • What is X \ X_1? Its the same as X / X_1? – Jesus moyano Nov 14 '19 at 21:22
  • Okay i got you, You mean the compliment. With numpy i cant do it with both sets because: this is the method: https://docs.scipy.org/doc/numpy/reference/generated/numpy.setdiff1d.html and only accept 1d arrays. – Jesus moyano Nov 14 '19 at 21:28