How do I print a numpy array?

Robert Kern robert.kern at gmail.com
Fri Dec 1 19:37:37 EST 2006


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.

-- 
Robert Kern

"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 Python-list mailing list