Ask Your Question

Revision history [back]

The method matrix_from_rows_and_columns will do just this; it is especially helpful if you don't want to use consecutive rows and/or columns:

sage: M = matrix(4, 4, range(16))
sage: M
[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]
[12 13 14 15]
sage: M.matrix_from_rows_and_columns([0,3], [1])
[ 1]
[13]
sage: M.matrix_from_rows_and_columns([0,3], [1,2])
[ 1  2]
[13 14]

The arguments are a pair: a list of rows to use and a list of columns to use.

The method matrix_from_rows_and_columns will do just this; it is especially helpful if you don't want to use consecutive rows and/or columns:

sage: M = matrix(4, 4, range(16))
sage: M
[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]
[12 13 14 15]
sage: M.matrix_from_rows_and_columns([0,3], [1])
[ 1]
[13]
sage: M.matrix_from_rows_and_columns([0,3], [1,2])
[ 1  2]
[13 14]

The arguments are a pair: a list of rows to use and a list of columns to use.use. The submatrix method can be used (in addition to the answers already provided) if you want consecutive rows and columns.