I found how to compare floats with equality here:
Compare `float` and `float64` in python
Working with floating point NumPy arrays for comparison and related operations
and in other similar questions.
But I can't find the best way how to compare correctly floats with threshold(greater or less).
Example: We want to check if elements in float matrix is less than float threshold.
eps = 0.1
xx = np.array([[1,2,3], [4,5,6], [7,8,9]])
yy = np.array([[1.1,2.1,3.1], [4.1,5.1,6.1], [7.1,8.2,9.3]])
dif = np.absolute(xx - yy)
print dif
print dif < eps
Print:
[[ 0.1 0.1 0.1]
[ 0.1 0.1 0.1]
[ 0.1 0.2 0.3]]
[[False False False]
[ True True True]
[ True False False]]
The only solution I found is to create a vectorize function and compare every element of matrix with treshold: first determine they're not equal and then compare with <
or >
.
Thanks for @MarkRansom.