For example, I have two ndarrays, the shape of train_dataset
is (10000, 28, 28)
and the shape of val_dateset
is (2000, 28, 28)
.
Except for using iterations, is there any efficient way to use the numpy array functions to find the overlap between two ndarrays?
Memory permitting you could use
broadcasting
, like so -Sample run -
If the elements are integers, you could collapse every block of
axis=(1,2)
in the input arrays into a scalar assuming them as linearly index-able numbers and then efficiently usenp.in1d
ornp.intersect1d
to find the matches.