# Revision history [back]

To get a square sub-matrix from a square matrix, you just need to delete an equal number of rows and columns.

Define the matrix. For example (starting from a copy-paste of the entries of the matrix...):

sage: m = matrix(ZZ, 4, [ZZ(a) for a in '2311123111233112'])
sage: m
[2 3 1 1]
[1 2 3 1]
[1 1 2 3]
[3 1 1 2]


Explore the available methods using dot and the tab key:

sage: m.<TAB>


Notice the methods delete_rows and delete_columns.

sage: m.delete_rows?
sage: m.delete_columns?


To enumerate subsets of size 2 of a set S, we can use Subsets(S, k=2).

Combining all this, write a loop to iterate over all possible numbers of rows and columns to delete.

sage: r = range(4)
sage: for k in [0 .. 4]:
....:     for i in Subsets(r, k=k):
....:         for j in Subsets(r, k=k):
....:             a = m.delete_rows(i).delete_columns(j)
....:             print a
....:             print det(a)
....: