Complete the code to import the QR decomposition function from scipy.
from scipy.linalg import [1] # Now you can use qr() to decompose matrices
The qr function from scipy.linalg performs QR decomposition.
Complete the code to perform QR decomposition on matrix A.
Q, R = qr([1])You pass the matrix A to the qr function to get matrices Q and R.
Fix the error in the code to correctly compute the QR decomposition and print Q.
from scipy.linalg import qr A = [[1, 2], [3, 4]] Q, R = qr([1]) print(Q)
The variable A must be passed as a single argument to qr. Passing the list of lists directly without brackets causes an error.
Fill both blanks to create a dictionary comprehension that maps each column index to the norm of that column in Q.
col_norms = {i: [1] for i in range(Q.shape[[2]])}The dictionary comprehension calculates the norm of each column i in Q. The number of columns is Q.shape[1].
Complete the code to create a dictionary comprehension that maps each row index to the sum of absolute values in that row of R, but only for rows where the sum is greater than 1.
row_sums = {i: sum(abs(R[i, :]) ) for i in range(R.shape[[1]]) if sum(abs(R[i, :])) > 1}The code sums the absolute values of all columns in each row i of R. The row count is R.shape[0]. The slice : selects all columns.