[Numpy-discussion] repr for numarray

Perry Greenfield perry at stsci.edu
Tue Jun 11 11:44:10 EDT 2002

While I'm flooding the mailing list with interface issues,
I thought I would air another one (again, for numarray only).

We've had some people internally complain that it does not
make sense for repr to always generate a string capable of
reconstructing the array. We often (usually) deal with
multi-megabyte arrays. Typing a variable interactively for
one of these arrays is invariably nonsensical. In such
cases the user would be much better served by a message
indicating the size, shape, type, etc. of the array than
all of its contents. 

Yet on the other hand, it is undeniably convenient to use
repr (by typing a variable) for small arrays interactively 
rather than using a print statement. This leads to 3 possible
proposals for handling repr:

1) Do what is done now, always print a string that when
eval'ed will recreate the array.

2) Only give summary information for the array regardless of
its size.

3) Print the array if it has fewer than THRESHOLD number of
elements, otherwise print a summary. THRESHOLD may be adjusted
by the user.

The last appears to be the most utilitarian to us, yet
'impure' somehow.  Certainly there are may objects for which
Python does not attempt to generate a string from repr that
could be used with eval to recreate them. On the other hand,
we are unaware of cases where repr sometimes does and sometimes
does not. For example, strings may also get very large, but
there is no threshold for generating the string.

What do people think the most desirable
solution? Keep in mind we intend to develop very efficient
functions that will convert arrays to and from ascii
representations (currently most of that code is in Python
and quite slow in numarray at the moment) so it will not be
necessary to use repr for this purpose. 

Only a few more issues to go, hopefully...


More information about the NumPy-Discussion mailing list