printing arrays in shell, and .py association with idle
Robert Kern
rkern at ucsd.edu
Tue May 17 04:42:50 EDT 2005
Paris Miles-Brenden wrote:
> I have been using python for the last 3 years and feel it to be an
> excellent programming language. However, I have run into a few snags or
> annoyances. I am currently creating a computational physics simulation
> which requires large arrays and am using numeric, although this is not a
> list for numeric, I think that my question falls under python in general.
>
>
> 1. My first problem is with printing these large arrays for debugging
> purposes. Is there any way to prevent the python shell from word
> wrapping single array print statements? I'm simply using:
>
> print hamiltonian
>
> where hamiltonian is an array of complex numbers. Changing window size
> (default or otherwise) does not change this, and I have found the option
> no-where.
Well this at least is a Numeric-specific question, not a general Python one.
Anyways, the string representation can be controlled by supplying the
appropriate callback. From Numeric.py (pardon any unfortunate linewraps):
#Use Konrad's printing function (modified for both str and repr now)
from ArrayPrinter import array2string
def array_repr(a, max_line_width = None, precision = None,
suppress_small = None):
return array2string(a, max_line_width, precision, suppress_small,
', ', 1)
def array_str(a, max_line_width = None, precision = None, suppress_small
= None):
return array2string(a, max_line_width, precision, suppress_small,
' ', 0)
multiarray.set_string_function(array_str, 0)
multiarray.set_string_function(array_repr, 1)
--
Robert Kern
rkern at ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
More information about the Python-list
mailing list