A 2D matrix can be represented as a list and a column count value in Python. For example, the 3x3 matrix 1 2 3 4 5 6 7 8 9 can be row-wise represented as ([1,2,3,4,5,6,7,8,9], 3), where the number 3...


A 2D matrix can be represented as a list and a column count value in Python.

For example, the 3x3 matrix


1 2 3
4 5 6
7 8 9


can be row-wise represented as ([1,2,3,4,5,6,7,8,9], 3), where the number 3

represents the number of columns in the matrix. Similarly,


1 3 5
2 4 6


becomes ([1,3,5,2,4,6], 3).


A submatrix can be defined as an (l,r,t,b) tuple, where l and r are left and

right column indices, and t and b are top and bottom row indices (all

inclusive). Write a function that takes a tuple containing the list

representing a matrix, and the column count of the matrix, along with another

tuple representing a specific submatrix, and returns the list representation of

the submatrix along with its column count as a tuple. For example, given


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 column indices 1 and 2 (both inclusive), and row indices 0 and 1 (both inclusive). So, the result becomes


2 3

6 7


which corresponds to ([2,3,6,7],2).
"""


A 2D matrix can be represented as a list and a column count value in Python.<br>For example, the 3x3 matrix<br>1 2 3<br>456<br>7 89<br>can be row-wise represented as ([1,2,3,4,5,6,7,8,9], 3), where the number 3<br>represents the number of columns in the matrix. Similarly,<br>1 35<br>2 4 6<br>becomes ([1,3,5,2,4,6], 3).<br>A submatrix can be defined as an (1,r,t,b) tuple, where 1 and r are left and<br>right column indices, and t and b are top and bottom row indices (ali<br>inclusive). Write a function that takes a tuple containing the list<br>representing a matrix, and the column count of the matrix, along with another<br>tuple representing a specific submatrix, and returns the list representation of<br>the submatrix along with its column count as a tuple. For example, given<br>submatrix(([1,2,3,4,5,6,7,8,9,10,11,12], 4), (1,2,0,1)) returns:<br>([2,3,6,7], 2)<br>because, ([1,2,3,4,5,6,7,8,9,10,11,12], 4) represents:<br>1<br>2<br>3<br>4<br>7 8<br>9 10 11 12<br>6<br>and (1,2,0,1) represents the submatrix between column indices 1 and 2 (both inclusive), and row indices o and 1 (both inclusive). So, the result becomes<br>2 3<br>6 7<br>which corresponds to ([2,3,6,7],2).<br>def submatrix(matrix, indices):<br>return # Remove this line to answer this question.<br>

Extracted text: A 2D matrix can be represented as a list and a column count value in Python. For example, the 3x3 matrix 1 2 3 456 7 89 can be row-wise represented as ([1,2,3,4,5,6,7,8,9], 3), where the number 3 represents the number of columns in the matrix. Similarly, 1 35 2 4 6 becomes ([1,3,5,2,4,6], 3). A submatrix can be defined as an (1,r,t,b) tuple, where 1 and r are left and right column indices, and t and b are top and bottom row indices (ali inclusive). Write a function that takes a tuple containing the list representing a matrix, and the column count of the matrix, along with another tuple representing a specific submatrix, and returns the list representation of the submatrix along with its column count as a tuple. For example, given 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 7 8 9 10 11 12 6 and (1,2,0,1) represents the submatrix between column indices 1 and 2 (both inclusive), and row indices o and 1 (both inclusive). So, the result becomes 2 3 6 7 which corresponds to ([2,3,6,7],2). def submatrix(matrix, indices): return # Remove this line to answer this question.
Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here