[Numpy-discussion] Is this a bug in repr ?
Tue Mar 15 13:26:14 CDT 2011
On Tue, Mar 15, 2011 at 13:10, Mark Sienkiewicz <firstname.lastname@example.org> wrote:
> Robert Kern wrote:
>> On Tue, Mar 15, 2011 at 12:39, Charles R Harris
>> <email@example.com> wrote:
>>> Yes, I think it is a bug. IIRC, it also shows up for object arrays.
>> It's extremely long-standing, documented, intentional behavior dating
>> back to Numeric.
>> |1> import Numeric
>> |2> a = Numeric.array( [ 16.50698631688883822 ] )
>> |3> print repr(a)
>> array([ 16.50698632])
>> You can disagree with the feature, but it's not a bug.
> So it is needed to maintain backward compatibility? (Still?)
No, it's an intentional feature, and the reasons for it then still
pertain now. It's a pragmatic compromise to display useful amounts of
information at the interactive prompt without overwhelming the user
with what is usually unimportant detail that would take up excessive
space. We also elide elements using "..." when there are too many
elements to display in a reasonable amount of time for the same
reason. You can control these settings using np.set_printoptions().
> In that case, would you agree that it is a bug for
> assert_array_almost_equal to use repr() to display the arrays, since it
> is printing identical values and saying they are different? Or is there
> also a reason to do that?
It should probably use np.array_repr(x, precision=16)
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion