[PYTHON MATRIX-SIG] More repr vs. str issues - Please Read!

Perry A. Stoll pas@xis.xerox.com
Mon, 3 Mar 1997 12:30:45 PST


> 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')"

-Perry



_______________
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________