[SciPy-user] numpy repr issue

Jeremy Sanders jeremy@jeremysanders....
Fri Feb 27 04:45:32 CST 2009

Hi - I wonder whether you consider this a bug (numpy 1.2.0 x86_64):

In [51]: repr(numpy.arange(10000))
Out[51]: 'array([   0,    1,    2, ..., 9997, 9998, 9999])'

I've found out that you can use numpy.set_printoptions to control this 
truncation behaviour, but the python documentation says:

Return a string containing a printable representation of an object. This is 
the same value yielded by conversions (reverse quotes). It is sometimes 
useful to be able to access this operation as an ordinary function. For many 
types, this function makes an attempt to return a string that would yield an 
object with the same value when passed to eval(), otherwise the 
representation is a string enclosed in angle brackets that contains the name 
of the type of the object together with additional information often 
including the name and address of the object. A class can control what this 
function returns for its instances by defining a __repr__() method.

Numpy doesn't obey this. It returns a string you can't do repr on to get 
back the original data. It's not a string in angle brackets either.

I've just hit a bug in pymc where truncated data is stored in its text 
database. It uses eval to read back the data.

This truncation causes silent data loss in numpy-using applications which 
assume the standard python behaviour of being able to eval a repr'd object. 
You won't see the problem unless your data starts being greater than 1000 

Shouldn't numpy change the default truncation so that no data are lost in 


More information about the SciPy-user mailing list