Question 2: Stacking (12 points)
Complete the stacking function, which takes two Matrix objects as input and returns a new Matrix object representing the augmented matrix of the inputs (i.e., it stacks the matrix of the second parameter at the end of the matrix of the first parameter). If X is an m x n matrix and Y is an m x n matrix, the augmented matrix M = [X|Y] is an m x (2n) matrix, in which the first n entries across a row of M correspond to X and the last n entries across a row of M correspond to Y.
[11 12 13 ... X1n]
[21 22 23 ... X2n]
[... ... ... ... ...]
[xm1 xm2 xm3 ... Xmn]
[Y11 Y12 Y13 ... Y1n]
[Y21 Y22 Y23 ... Y2n]
[... ... ... ... ...]
[Ym1 Ym2 Ym3 ... Ymn]
The following is a view of how the function looks in the Matrix.py file:
def stacking(self, other):
"""
Returns a new Matrix object that represents the augmented matrix between self.matrix and other.matrix.
Pre-req: self.num_rows == other.num_rows and self.num_columns == other.num_columns and self.num_rows == self.num_columns
"""
# Code for stacking function goes here
For this method, you can safely assume that the matrices of both input objects have the same dimensions (i.e., self.num_rows == other.num_rows and self.num_columns == other.num_columns). Furthermore, both matrices are square matrices (i.e., self.num_rows == self.num_columns). These prerequisites are very important because they differ from the stacking method of the recorded video lecture. Please remember that in the video, we stacked the vector b as the last column of the matrix A. Here, for this assignment (and in order to compute the inverse of the matrix), we need to stack the identity matrix I to the matrix A.