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.
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.
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)