[PYTHON MATRIX-SIG] Slicing

Jim Fulton, U.S. Geological Survey jfulton@usgs.gov
Wed, 20 Sep 1995 09:18:08 -0400


On Tue, 19 Sep 1995 22:18:43 -0700 
Graham Hughes said:
> I think I figured out how to get the slicing without any modification of the
> existing Python base to work.

The original proposal *already* says how to get slicing without any
modifications to the core language.
 
> 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.

See my earlier post.  Matrices are stored by sub-matrix.  Storage by
"rows" or by "columns" is a question of interpretation.  Under my
system of interpretation, matrices are stored by column (in Fortran,
C, and the proposed Python extension).

> 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

What does this mean?
 
> 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

Do you mean like: [[1,2],[2,3],[3,4]]?
 
> Given this, slicing is relatively easy,

How?

> and [:] will return a transpose of
> the internal storage.

Why?  This would be inconsistent with other sequence types.

> So m[0:1] will return in original form [[1],[2],[3]] or
> 
>         1
> 
>         2
> 
>         3

What has this gained? (Perhaps an example with greater than two rows
and columns would be better?)

Let's be clear about the goal.  Goven a matrix that looks (by rows or
by columns, take your pick) like this:

  0 10 20 30  
  1 11 21 31 
  2 12 22 32 
  3 13 23 33 

one wants to be able to access a matrix that looks like this:

    11 21 
    12 22 

Some even want to be able to access a matrix that looks like this:

  1 21
  3 23

or even this:

  0 30  
  3 33 

and so on. And, of course, this needs to generalize to higher dimensions.

Also, modification to this access should be reflected in the matrix
being accessed.

I don't see how switching indexes solves this problem.

Jim

=================
MATRIX-SIG  - SIG on Matrix Math for Python

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