Print precision?

Fernando Pérez fperez528 at yahoo.com
Fri May 24 21:47:30 EDT 2002


Damian Menscher wrote:

> I'm debugging my program that depends on the Numeric/LinearAlgebra
> packages.  In order to get an idea of what is going on, I just use
> lots of print statements.  But when you're printing a largish
> (32x32) matrix, the 8 decimal places given by default can take
> more space than they're worth.  Is there a simple way to cut this
> down to a more reasonable value (like zero)?
> 
> I guess I *could* write a function that prints each element
> separately....
> for i in range(32):
> print "%.1f %.1f %.1f %.1f ..."%(m[i,0], m[i,1], m[i,2]....)
> But that just seems silly.
> 
> 
> On a related note, is there a way to change the default line width?
> Even if I expand my xterm to 200+ chars, Python wraps the matrix
> output at 80.

Numeric arrays have their own printing routines, python only prints a string 
it gets from them. So you'd have to hack into Numeric a bit. If you're 
planning on it, let me suggest you take a look at ipython at:

http://www-hep.colorado.edu/~fperez/ipython/

I've already put in the hooks for a modified Numeric array printer, so it 
would be only a matter of adding the code. The framework is in place. And for 
the kind of numerical/analysis work I suspect you do, ipython has many 
features which will probably help you a lot. That's my main use of it and why 
I wrote it to begin with.

On a vein related to your work: I use it interactively to look at finite 
temperature vacuum topology (pure gauge), here are some quick and dirty 
screenshots:
http://www-hep.colorado.edu/~fperez/pub/topo_viz_sample.jpg
http://www-hep.colorado.edu/~fperez/pub/topo_2412.b585m008.36.1000.slices/
http://www-hep.colorado.edu/~fperez/pub/topo_vol_ray.jpg

The first is a single 3-d slice visualized, the second is a set of frames of 
the full lattice (24^3x12) sliced along the x direction and the 3rd is a 
fancy volume rendered version of the first.

If you are interested in the code to do that, drop me  a line. It has already 
code for loading MILC-format topological density data, and it's easy to add 
writers for other formats. Its still 'internal use code', so not very 
commented (right now I was modifying it to look at chiral/fermionic density) 
but it should be clear enough for you to play with.

Cheers,

f.



More information about the Python-list mailing list