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

Konrad Hinsen hinsen@ibs.ibs.fr
Tue, 4 Mar 1997 11:36:25 +0100


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

Fine for this example. But what will a float array look like?
With every element formatted individually, the result will be a mess.
And what happens to higher-rank arrays?

To make the output of repr() clear for the user, it must be produced
in a similar way to how str() works now. In fact, it would be easy
to modify the array printer to produce a format like the one above.

One final comment about "a format that is a legal input
representation".  That sounds like a neat idea at first, but doesn't
really make much sense in an extensible language. In fact, the
representation shown above is legal input only if you have executed
"from Numeric import *" before. And there might be a dozen modules
that implement a data type called "array". So the importance of repr()
is more to aid the *user* in recognizing the type, not the interpreter.

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-4.76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

_______________
MATRIX-SIG  - SIG on Matrix Math for Python

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