0
0
SciPydata~10 mins

LU 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 LU decomposition function from scipy.

SciPy
from scipy.linalg import [1]
Drag options to blanks, or click blank then click option'
Aeig
Bsvd
Cinv
Dlu
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated functions like svd or eig.
Using functions from other modules.
2fill in blank
medium

Complete the code to perform LU decomposition on matrix A.

SciPy
P, L, U = [1](A)
Drag options to blanks, or click blank then click option'
Alu
Bsvd
Cinv
Deig
Attempts:
3 left
💡 Hint
Common Mistakes
Using svd or eig instead of lu.
Trying to call lu without arguments.
3fill in blank
hard

Fix the error in the code to correctly get the lower triangular matrix L from LU decomposition.

SciPy
_, [1], _ = lu(A)
Drag options to blanks, or click blank then click option'
AU
BL
CP
DQ
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning U or P to the variable for L.
Using an undefined variable name.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each row index to the sum of the corresponding row in matrix U.

SciPy
row_sums = {i: [1] for i in range(U.shape[0]) if [2] > 0}
Drag options to blanks, or click blank then click option'
Asum(U[i])
Bi
DU[i]
Attempts:
3 left
💡 Hint
Common Mistakes
Using the entire row U[i] as a key.
Using the sum as the key instead of the value.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each column index to the maximum value in that column of matrix L, but only if the max is greater than 0.

SciPy
col_max = {j: max(L[:, [1]]) for j in range(L.shape[[2]]) if max(L[:, j]) [3] 0}
Drag options to blanks, or click blank then click option'
Aj
B1
C>
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using row index instead of column index.
Using incorrect comparison operators.