thouis / numpy-trac-migration

numpy Trac to github issues migration
2 stars 3 forks source link

assert_array_almost_equal prints low precision (migrated from Trac #1774) #3322

Open thouis opened 12 years ago

thouis commented 12 years ago

Original ticket http://projects.scipy.org/numpy/ticket/1774 Reported 2011-03-16 by atmention:stsci-sienkiew, assigned to unknown.

If you do this, a=numpy.array( [ 16.50698631688883822 ] ) b=numpy.array([ 16.50698632 ]) numpy.testing.assert_array_almost_equal(a,b,decimal=15)

it says

AssertionError: 
Arrays are not almost equal to 15 decimals

(mismatch 100.0%)
 x: array([ 16.50698632])
 y: array([ 16.50698632])

In discussion on the mailing list, Robert Kern gave a good explanation of why this happens and suggested that instead of repr(), It should probably use np.array_repr(x, precision=16)

Instead of fixing the precision at 16, maybe it should use the decimal parameter to choose the precision to print. The point being that if the arrays are not almost equal, we should be able to see which elements did and did not match.

thouis commented 12 years ago

Comment in Trac by atmention:rgommers, 2011-03-24