python - find 2d elements in a 3d array which are similar to 2d elements in another 3d array -
i have 2 3d arrays , want identify 2d elements in 1 array, have 1 or more similar counterparts in other array. this works in python 3: import numpy np import random np.random.seed(123) = np.round(np.random.rand(25000,2,2),2) b = np.round(np.random.rand(25000,2,2),2) a_index = np.zeros(a.shape[0]) in range(a.shape[0]): b in range(b.shape[0]): if np.allclose(a[a,:,:].reshape(-1, a.shape[1]), b[b,:,:].reshape(-1, b.shape[1]), rtol=1e-04, atol=1e-06): a_index[a] = 1 break np.nonzero(a_index)[0] but of course approach awfully slow. please tell me, there more efficient way (and is). thx. you trying all-nearest-neighbor type query. has special o(n log n) algorithms, i'm not aware of python implementation. can use regular nearest-neighbor o(n log n) bit slower. example scipy.spatial.kdtree or ckdtree . import numpy np import random np.random.seed(123) = np.round(np.random.rand(25000,2,2),2) b = np.round...