0

I'm using Python3 and numpy and I'm doing the following:

diff1 = np.abs(self.trainX - sample_repeated)
diff2 = np.abs(sample_repeated - self.trainX)
print("diff1 equals diff2?")
if(np.array_equal(diff1,diff2)): 
    print("Yes")
else:
    print("No")

I expected diff1 to be equal to diff2. Any idea why the code always prints "No"? All the arrays have the same same (self.trainX, sample_repeated, diff1 and diff2).

NB: numpy docs report that array_equal is "True if two arrays have the same shape and elements, False otherwise."

Solved: you arrays was uint8 and that leads to overflow. You must cast them to int before

user1315621
  • 3,044
  • 9
  • 42
  • 86

1 Answers1

0

Solved: you arrays was uint8 and that leads to overflow. You must cast them to int before

user1315621
  • 3,044
  • 9
  • 42
  • 86