How do I print a numpy array?

David E. Konerding DSD staff dek at oliver.lbl.gov
Mon Dec 4 12:21:14 EST 2006


On 2006-12-02, Robert Kern <robert.kern at gmail.com> wrote:
> Beliavsky wrote:
>> When I print an array in any language, I (and I think most programmers)
>> expect by default to have all elements displayed. Matlab, R, and
>> Fortran 95 have somewhat similar arrays to numpy, and that is what they
>> do. I don't remember Numeric summarizing arrays by default. R has a
>> "summary" function as well as a "print" function.
>
> There are pretty serious problems with interactive use and large arrays.
> Formatting the string for a very large array can take a fair bit of time, often
> much more than the computation that generated it. This has been a long-standing
> frustration of many Numeric users. At the interactive prompt, if the statement
> you just entered is taking a long time to execute and you Ctrl-C, odds are, the
> traceback points you right in the middle of array2string(), not anything in the
> actual computation itself. Since the interactive prompt prints things out
> without the user explicitly asking for it, it's not enough simply to have two
> functions available.
>
> numarray set the default to summarize, and numpy kept numarray's choice.

I 100% approve of the summarization by default.  It has saved me *many* times.

Dave



More information about the Python-list mailing list