repr for numarray

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... Perry

On June 11, 2002 02:43 pm, Perry Greenfield wrote:
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
I vote for number 3, and have no hang-ups about any real or perceived "impurity". This is an issue that I deal with daily. Scott -- Scott M. Ransom Address: McGill Univ. Physics Dept. Phone: (514) 398-6492 3600 University St., Rm 338 email: ransom@physics.mcgill.ca Montreal, QC Canada H3A 2T8 GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989

I would also be inclined toward option 3 with the caveat that THRESHOLD=None should print all the values for the purists out there (or if you want to use repr to dump the array to some sort of flat file). -tim
On June 11, 2002 02:43 pm, Perry Greenfield wrote:
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
I vote for number 3, and have no hang-ups about any real or perceived "impurity". This is an issue that I deal with daily.
Scott
-- Scott M. Ransom Address: McGill Univ. Physics Dept. Phone: (514) 398-6492 3600 University St., Rm 338 email: ransom@physics.mcgill.ca Montreal, QC Canada H3A 2T8 GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989
_______________________________________________________________
Multimillion Dollar Computer Inventory Live Webcast Auctions Thru Aug. 2002 - http://www.cowanalexander.com/calendar
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion

MA users seem to all be happy with the facility in MA for limiting printing. >>> x=MA.arange(20) >>> x array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,]) >>> MA.set_print_limit(10) >>> x array([0,1,2,3,4,5,6,7,8,9,] + 10 more elements) >>> print x [0,1,2,3,4,5,6,7,8,9,] + 10 more elements >>> MA.set_print_limit(0) # no limit >>> x array([ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19]) > -----Original Message----- > From: numpy-discussion-admin@lists.sourceforge.net > [mailto:numpy-discussion-admin@lists.sourceforge.net] On > Behalf Of Tim Hochberg > Sent: Tuesday, June 11, 2002 12:29 PM > To: numpy-discussion@lists.sourceforge.net > Subject: Re: [Numpy-discussion] repr for numarray > > > > I would also be inclined toward option 3 with the caveat that > THRESHOLD=None should print all the values for the purists > out there (or if you want to use repr to dump the array to > some sort of flat file). > > -tim > > > > On June 11, 2002 02:43 pm, Perry Greenfield wrote: > > > > > 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 > > > > I vote for number 3, and have no hang-ups about any real or > perceived > > "impurity". This is an issue that I deal with daily. > > > > Scott > > > > > > -- > > Scott M. Ransom Address: McGill Univ. Physics Dept. > > Phone: (514) 398-6492 3600 University St., Rm 338 > > email: ransom@physics.mcgill.ca Montreal, QC Canada H3A 2T8 > > GPG Fingerprint: 06A9 9553 78BE 16DB 407B FFCA 9BFA B6FF FFD3 2989 > > > > _______________________________________________________________ > > > > Multimillion Dollar Computer Inventory > > Live Webcast Auctions Thru Aug. 2002 - > http://www.cowanalexander.com/calendar > > > > > > > > _______________________________________________ > > Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net > > https://lists.sourceforge.net/lists/listinfo/numpy-discussion > > > > > _______________________________________________________________ > > Multimillion Dollar Computer Inventory > Live Webcast Auctions Thru Aug. 2002 - > http://www.cowanalexander.com/calendar > > > > > _______________________________________________ > Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/numpy-discussion >

"Perry Greenfield" <perry@stsci.edu> writes:
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
I don't see the problem. The documented behaviour would be that it doesn't allow reconstruction. If for some arrays that works nevertheless, who is going to complain? BTW, it would be nice if the summary would contain the values of some elements, to allow a quick identification of NaN arrays and similar problems.
does not. For example, strings may also get very large, but there is no threshold for generating the string.
Right. But in practice strings rarely do get that large. Arrays do. Konrad. -- ------------------------------------------------------------------------------- Konrad Hinsen | E-Mail: hinsen@cnrs-orleans.fr Centre de Biophysique Moleculaire (CNRS) | Tel.: +33-2.38.25.56.24 Rue Charles Sadron | Fax: +33-2.38.63.15.17 45071 Orleans Cedex 2 | Deutsch/Esperanto/English/ France | Nederlands/Francais -------------------------------------------------------------------------------
participants (6)
-
Konrad Hinsen
-
Paul F Dubois
-
Perry Greenfield
-
Scott Ransom
-
Tim Hochberg
-
Travis Oliphant