Find differences between arrays, with probability of variation
Good Afternoon folks, I'm reading about the numpy library's setdiff1d function ( https://docs.scipy.org/doc/numpy/reference/generated/numpy.setdiff1d.html).
It basically serves to express the different values between 2 arrays, for example (found in the link itself):
>>> a = np.array([1, 2, 3, 2, 4, 1])
>>> b = np.array([3, 4, 5, 6])
>>> np.setdiff1d(a, b)
array([1, 2])
I would like to know if it has any function that allows you to insert a percentage of variation in the values to be compared.
I explain, as shown in for example, the setdiff1d function will return values that are exactly different between the 2 arrays.
However, in case I am working with floats, and I want to allow a percentage of variation between these values, for example, consider 3.35 and 3.34 between two arrays as equal values, do you have any specific function to work in this way, where I can set as an argument a margin of variation between the values to be compared?
Grateful.
1 answers
Tries like this:
limit = 0.01
np.unique(a[(np.abs(np.subtract.outer(a,b)) > limit).all(1)])