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

Jim Hugunin hugunin@mit.edu
Mon, 3 Mar 1997 14:37:22 -0500


This repr vs. str discussion might seem esoteric, but it will affect the 
day to day interactions of everybody who works with NumPy.  Please do read 
the following and let me know if this will have a negative impact on your 
work.

After all of this discussion, I've decided that I don't like the current 
way that strings are displayed in Unix interpreters (which is good, because 
the way they are displayed only works because of a bug in my code which 
needs to be fixed one way or another).  I find that when I "really" want to 
know what an array looks like I'll usually type "repr(a)" anyway.  I also 
really like the current property that the repr of an array is something 
that can be typed into python to get an equivalent array back.

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

>>> print a # same as str(a)
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

>>>

I realize that this seems a little bit uglier than the current behavior 
(especially to those used to programs like matlab).  Nonetheless, I think 
that this behavior is much more "pythonesque".  I think that this new 
output notation will much better fit into the python world where everything 
is not in fact an array.

Let me know what you think - Jim


_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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