0
0
SciPydata~10 mins

QR decomposition in SciPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the QR decomposition function from scipy.

SciPy
from scipy.linalg import [1]

# Now you can use qr() to decompose matrices
Drag options to blanks, or click blank then click option'
Aqr
Bsvd
Ceig
Dinv
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong function like svd or eig.
Trying to import from numpy.linalg instead of scipy.linalg.
2fill in blank
medium

Complete the code to perform QR decomposition on matrix A.

SciPy
Q, R = qr([1])
Drag options to blanks, or click blank then click option'
Aqr
BQ
CA
DR
Attempts:
3 left
💡 Hint
Common Mistakes
Passing Q or R instead of A to the qr function.
Passing the function name qr instead of the matrix.
3fill in blank
hard

Fix the error in the code to correctly compute the QR decomposition and print Q.

SciPy
from scipy.linalg import qr

A = [[1, 2], [3, 4]]
Q, R = qr([1])
print(Q)
Drag options to blanks, or click blank then click option'
AA
B[1, 2], [3, 4]
Cqr
DQ
Attempts:
3 left
💡 Hint
Common Mistakes
Passing multiple lists instead of a single matrix variable.
Passing the function name or Q instead of the matrix.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each column index to the norm of that column in Q.

SciPy
col_norms = {i: [1] for i in range(Q.shape[[2]])}
Drag options to blanks, or click blank then click option'
Anp.linalg.norm(Q[:, i])
B0
C1
DQ.shape[0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong axis index for shape.
Calculating norm on rows instead of columns.
5fill in blank
hard

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.

SciPy
row_sums = {i: sum(abs(R[i, :]) ) for i in range(R.shape[[1]]) if sum(abs(R[i, :])) > 1}
Drag options to blanks, or click blank then click option'
A:]
B0
C:
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect slice notation like ':]' or '1'.
Using the wrong axis index for shape.