Graham Hughes graham@fishnet.net
Tue, 19 Sep 1995 22:18:43 -0700

I think I figured out how to get the slicing without any modification of the
existing Python base to work.

Earlier it was said that m[i:j][k] wouldn't work because of the precedence
rules. I think one way of avoiding these problems is to look at the slicing
this way:

Assume for the moment that sequences of sequences are stored by row, i.e.
like C. To get the slicing to work properly, we have to slice by *columns*.
As an example, suppose we have [[1,2,3],[2,3,4]], or 

        1       2       3

        2       3       4

if we accept the original premise. The matrix class will store it this way
internally. However, every interaction with the user *must* make the matrix
look like this:

        1       2

        2       3

        3       4

Given this, slicing is relatively easy, and [:] will return a transpose of
the internal storage. So m[0:1] will return in original form [[1],[2],[3]] or




This works great for slices. However, assigning to individual elements is a
tad tricker... Note that a special case for single dimension arrays will
simply do standard slicing, as the effect is the same.

Graham Hughes <graham@fishnet.net>  Home page http://www.fishnet.net/~graham/
``I think it would be a good idea.'' -- Mahatma Ghandi, when asked what he
                                        thought of Western civilization
finger for PGP public key.

MATRIX-SIG  - SIG on Matrix Math for Python

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