[PYTHON MATRIX-SIG] More repr vs. str issues - Please Read!
Jim Hugunin
hugunin@mit.edu
Mon, 3 Mar 1997 15:40:15 -0500
Perry Stoll writes:
>
> > The problem with the current repr function is that it doesn't display
the
> > internal structure of the array which leaves out a lot of valuable
> > information. To fix all of these problems in one fell swoop ;-), I
propose
> > the following new behavior:
> >
> >>>> from Numeric import *
> >>>> a = identity(10)
> >>>> a # same as repr(a)
> > array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
> > [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
> > [0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
> > [0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
> > [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
> > [0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
> > [0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
> > [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
> > [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
> > [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]], 'l')
>
> Will repr format it as above, i.e. including the newlines? Currently
> it returns a single string without newlines, basically nullifying an
> easy scan of the internal structure.
>
> # currently, repr does this:
> >>> repr(a)
> "array([[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0,
0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1,
0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]], 'l')"
Yes! Adding these new lines to repr's format is basically the grand idea I
had this weekend to provide a repr format that was both in tune with the
rest of python, and yet showed the internal structure of the array. The
format will look basically like the currently printed form of an array with
a few commas and brackets added (in fact, for the first version I plan to
just make these small changes to Konrad's current array print function to
use as the array repr function).
-Jim
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________