I have two arrays both from text file. By observation, it totally looks the same. However when I test the equivalence of the two arrays, they fail - element wise, shape wise etc.. I used the numpy test answered here.
Here are the two matrices.
import numpy as np
class TextMatrixAssertions(object):
def assertArrayEqual(self, dataX, dataY):
x = np.loadtxt(dataX)
y = np.loadtxt(dataY)
if not np.array_equal(x, y):
raise Exception("array_equal fail.")
if not np.array_equiv(x, y):
raise Exception("array_equiv fail.")
if not np.allclose(x, y):
raise Exception("allclose fail.")
dataX = "MyMatrix.txt"
dataY = "MyMatrix2.txt"
test = TextMatrixAssertions()
test.assertArrayEqual(dataX, dataY)
I want to know if there is really some difference between the two arrays or if not, what is causing the failures.
print(repr(x))andprint(repr(y))and see if that makes it more clear how the values differ. docs.python.org/3/library/functions.html#repr tries to print "a string that would yield an object with the same value when passed to eval()"raisestatements abort the execution of your method, right? So in casearray_equal()returnsFalse,allclose()is never reached.