On Fri, Feb 29, 2008 at 12:24 PM, Dan Christensen <[EMAIL PROTECTED]> wrote: > In numpy: > > In [11]: A[2:4] > Out[11]: > array([[ 1, 1, 2, -1], > [ 2, -1, 1, -1]]) > > (Or A[2:4,0:4].) > > > >>> # a column > >>> sage: A.matrix_from_rows_and_columns([1..2],[0..0]) > >>> [14] > >>> [ 1] > > In numpy it's A[1:3,0].
SAGE now tries to support numpy (and matlab)-style indexing, by poking at its underlying __getitem__ and __getslice__ (thanks to a suggestion by William): {{{ sage: m=[(1, -2, -1, -1,9), (1, 8, 6, 2,2), (1, 1, -1, 1,4), (-1, 2, -2, -1,4)];M= matrix(m) sage: M [ 1 -2 -1 -1 9] [ 1 8 6 2 2] [ 1 1 -1 1 4] [-1 2 -2 -1 4] Get The 2 x 2 submatrix of M, starting at row index and column index 1 sage: M[1:3,1:3] [ 8 6] [ 1 -1] Get the 2 x 3 submatrix of M starting at row index and column index 1: sage: M[1:3,[1..3]] [ 8 6 2] [ 1 -1 1] Get the second column of M: sage: M[1:,0] [ 1] [ 1] [-1] sage: M[range(2),:] [ 1 -2 -1 -1 9] [ 1 8 6 2 2] sage: M[range(2),4] [9] [2] sage: M[range(3),range(5)] [ 1 -2 -1 -1 9] [ 1 8 6 2 2] [ 1 1 -1 1 4] sage: M[3,range(5)] [-1 2 -2 -1 4] sage: M[3,:] [-1 2 -2 -1 4] sage: M[3,4] 4 }}} Please review the patch at http://trac.sagemath.org/sage_trac/ticket/2355 and help me shake out any bugs that I might have missed or possible speedups, etc. I guess it's safe to erase the submatrix command, although we could make it call __getitem__ if we chose to keep it. Thoughts? didier --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---