By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,866 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

How do I print a numpy array?

P: n/a
How do you print a numpy array?

I tried the obvious print a, print `a`, and print str(a), but
none of them work on anything other than trivially small
arrays. Most of my real data is elided and replaced with
ellipses.

--
Grant Edwards grante Yow! I want to kill
at everyone here with a cute
visi.com colorful Hydrogen Bomb!!
Dec 1 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Grant Edwards wrote:
How do you print a numpy array?

I tried the obvious print a, print `a`, and print str(a), but
none of them work on anything other than trivially small
arrays. Most of my real data is elided and replaced with
ellipses.
You might want to ask numpy questions on the numpy list:

http://www.scipy.org/Mailing_Lists

Use numpy.set_printoptions(threshold=sys.maxint) to disable all summarization.

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

Dec 1 '06 #2

P: n/a
On 2006-12-01, Robert Kern <ro*********@gmail.comwrote:
Grant Edwards wrote:
>How do you print a numpy array?
You might want to ask numpy questions on the numpy list:

http://www.scipy.org/Mailing_Lists
I tried, but it doesn't seem to be available through gmane.org.
Use numpy.set_printoptions(threshold=sys.maxint) to disable
all summarization.
Thanks.

--
Grant Edwards grante Yow! I've got to get
at these SNACK CAKES to NEWARK
visi.com by DAWN!!
Dec 1 '06 #3

P: n/a

Robert Kern wrote:
Grant Edwards wrote:
How do you print a numpy array?

I tried the obvious print a, print `a`, and print str(a), but
none of them work on anything other than trivially small
arrays. Most of my real data is elided and replaced with
ellipses.

You might want to ask numpy questions on the numpy list:

http://www.scipy.org/Mailing_Lists

Use numpy.set_printoptions(threshold=sys.maxint) to disable all summarization.
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.

Dec 1 '06 #4

P: n/a
Grant Edwards wrote:
On 2006-12-01, Robert Kern <ro*********@gmail.comwrote:
>Grant Edwards wrote:
>>How do you print a numpy array?
>You might want to ask numpy questions on the numpy list:

http://www.scipy.org/Mailing_Lists

I tried, but it doesn't seem to be available through gmane.org.
Yes, it is.

http://dir.gmane.org/gmane.comp.python.numeric.general

Did you have a specific problem accessing it? I can access it just fine. I think
you may have to subscribe to the list to post (otherwise we get too much spam).
Of course, you can turn off mail delivery if you only want to go through GMane.

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

Dec 2 '06 #5

P: n/a
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

Dec 2 '06 #6

P: n/a
On 2006-12-02, Robert Kern <ro*********@gmail.comwrote:
Grant Edwards wrote:
>On 2006-12-01, Robert Kern <ro*********@gmail.comwrote:
>>Grant Edwards wrote:
How do you print a numpy array?
>>You might want to ask numpy questions on the numpy list:

http://www.scipy.org/Mailing_Lists

I tried, but it doesn't seem to be available through gmane.org.

Yes, it is.

http://dir.gmane.org/gmane.comp.python.numeric.general
I was looking for the "numpy-discussion" mailing list. It
didn't occur to me that it was spelled "numeric.general".

--
Grant Edwards grante Yow! Th' MIND is the Pizza
at Palace of th' SOUL
visi.com
Dec 2 '06 #7

P: n/a
Grant Edwards wrote:
On 2006-12-02, Robert Kern <ro*********@gmail.comwrote:
>Grant Edwards wrote:
>>On 2006-12-01, Robert Kern <ro*********@gmail.comwrote:
Grant Edwards wrote:
How do you print a numpy array?
You might want to ask numpy questions on the numpy list:

http://www.scipy.org/Mailing_Lists
I tried, but it doesn't seem to be available through gmane.org.
Yes, it is.

http://dir.gmane.org/gmane.comp.python.numeric.general

I was looking for the "numpy-discussion" mailing list. It
didn't occur to me that it was spelled "numeric.general".
Yeah, GMane likes to apply their own naming system. Fortunately, they have a
little search tool that will locate the right newsgroup given "numpy-discussion":

http://gmane.org/find.php

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

Dec 2 '06 #8

P: n/a
On 2006-12-02, Robert Kern <ro*********@gmail.comwrote:
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
Dec 4 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.