and I would like to extract from it the first block 2x2 submatrix, ie
[0 1]
[0 0]
Any ideas on how to do this?
didier
From the reference manual:
matrix_from_rows_and_columns( )
Return the matrix constructed from self from the given rows and columns.
sage: M = MatrixSpace(Integers(8),3,3)
sage: A = M(range(9)); A
[0 1 2]
[3 4 5]
[6 7 0]
sage: A.matrix_from_rows_and_columns([1], [0,2])
[3 5]
sage: A.matrix_from_rows_and_columns([1,2], [1,2])
[4 5]
[7 0]
Note that row and column indices can be reordered or repeated:
sage: A.matrix_from_rows_and_columns([2,1], [2,1])
[0 7]
[5 4]
For example here we take from row 1 columns 2 then 0 twice, and do
this 3 times.
sage: A.matrix_from_rows_and_columns([1,1,1],[2,0,0])
[5 3 3]
[5 3 3]
[5 3 3]
>
> didier
>
>
> >
>
> matrix_from_rows_and_columns( )
Thanks, I knew there was something I was missing. Any chance of
aliasing this function to "submatrix()"? Because
"matrix_from_rows_and_columns()" feels clunky...
didier
No, because it is not a submatrix in general. For example:
sage: a = random_matrix(QQ,3,4); a
[-1/2 1 0 0]
[ -1 -1 2 2]
[-1/2 1/2 -1 0]
sage: a.matrix_from_columns([0,0,0,1,3])
[-1/2 -1/2 -1/2 1 0]
[ -1 -1 -1 -1 2]
[-1/2 -1/2 -1/2 1/2 0]
Let me know if this function is too slow of a base ring that you're
using -- it can be optimized.
William
i know William has responded, but i agree with this. some time ago i was
looking for this same feature and my first inclination was to look for a
function called "submatrix". it actually took me a long time to discover
the function i was looking for. perhaps we could add submatrix and
implement it in terms of matrix_from_rows_and_columns. better yet, is it
possible to support multiple slices?
M = matrix(...)
M[1:2, 1:3]
that would be very nice. if that's possible, what is the notation for the
"full slice" -- perhaps something like
M[:,1:3]
?
i also remember thinking it would be useful to have a "minor" function,
but i don't remember what i wanted it for now. this could also be
implemented easily in terms of matrix_from_rows_and_columns (or
submatrix).
-kyle