You could do it as shown below. If a
and b
get large, this is going to need lots of memory (on the order of the product of the sizes of a and b). Maybe you could loop over into small-enough chunks of b if that's a problem.
import numpy as np
def in1d_tol(a,b,tol):
d=np.abs(a-b[:,np.newaxis])
return np.any(d<=tol, axis=0)
a = np.array([1.011, 2.000, 3.001])
b = np.array([1.01, 3.00])
c = in1d_tol(a,b,0.01)
print c