On Tue, Mar 15, 2011 at 10:20 AM, Mark Sienkiewicz <sienk...@stsci.edu>wrote:
> The usual expectation is that (when possible) repr() returns a value > that you can eval() to get the original data back. But, > > >>> from numpy import * > >>> a = array( [ 16.50698631688883822 ] ) > >>> b = eval(repr(a)) > >>> a-b > array([ -3.11116111e-09]) > >>> import numpy.testing > >>> numpy.testing.assert_array_almost_equal(a,b,decimal=15) > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "/usr/stsci/pyssgdev/2.7/numpy/testing/utils.py", line 775, in > assert_array_almost_equal > header=('Arrays are not almost equal to %d decimals' % decimal)) > File "/usr/stsci/pyssgdev/2.7/numpy/testing/utils.py", line 618, in > assert_array_compare > raise AssertionError(msg) > AssertionError: > Arrays are not almost equal to 15 decimals > > (mismatch 100.0%) > x: array([ 16.50698632]) > y: array([ 16.50698632]) > >>> > > I noticed this because a bunch of tests failed exactly this way. Of > course, the problem is that assert_array_almost_equal does not print > with the precision that it compared, which in turn happens because it > just uses repr() to convert the array. > > I would expect that repr would print the values at least to the > resolution that they are stored, so I think this is a bug. > > This happens with the current trunk of numpy in python 2.7 on Red Hat > Enterprise linux in 32 and 64 bits, and on Macintosh Leopard in 32 > bits. I did not try any other configuration. > > Yes, I think it is a bug. IIRC, it also shows up for object arrays. Chuck
_______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion