import numpy as np
a = np.array([[1., 2., 3.],
[4., 5., 'a']], dtype=object)
b = np.array([[1.00000001, 2., 3.],
[4., 5., 'a']], dtype=object)
print(a == b)
actual output:
[[False True True]
[ True True True]]
expected output (since 1.00000001 is close enough to 1):
[[True True True]
[True True True]]
I cannot use numpy.isclose() because there is non-numerical part in the array.
a.ravel()[:-1].astype(float).iscloseuses the difference, and also checks for floats likeinf, which is why it needs the numeric dtype. Or you could leave the valuesobjectdtype, and do your own test of the differencesa.ravel()[:-1]