I’m trying to express a matrix by using Python, for example a 3X3 matrix with numbers:
1 2 3
4 5 6
7 8 9
can be also writen as ([1,2,3,4,5,6,7,8,9], 3), where number 3
shows the number of columns in the matrix. I AM NOT TRYING TO PRINT THE PATTERN OF THE MATRIX. Another example,
1 3 5
2 4 6
becomes ([1,3,5,2,4,6], 3).
This submatrix can be defined as a (l,r,t,b) tuple, where l and r are left and
right columns, and t and b are top and bottom rows (all
inclusive).
Similarly,
submatrix(([1,2,3,4,5,6,7,8,9,10,11,12], 4), (1,2,0,1)) returns:
([2,3,6,7], 2)
because, ([1,2,3,4,5,6,7,8,9,10,11,12], 4) represents:
1 2 3 4
5 6 7 8
9 10 11 12
and (1,2,0,1) represents the submatrix between columns 1 and 2 (both inclusive), and rows 0 and 1 (both inclusive). So, the result becomes
2 3
6 7
which is also equal to ([2,3,6,7],2).
I am also trying to write it with the definition function. Like so: def submatrix(matrix, indices)
How can this be achieved?