Challenge - 5 Problems
Sparse Matrix Factorization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of sparse LU factorization
What is the shape of the L and U factors after performing LU factorization on a 4x4 sparse matrix?
SciPy
import numpy as np from scipy.sparse import csc_matrix from scipy.sparse.linalg import splu A = csc_matrix(np.array([[4, 0, 0, 0], [3, 5, 0, 0], [0, 1, 7, 0], [0, 0, 2, 6]])) lu = splu(A) L_shape = lu.L.shape U_shape = lu.U.shape print(L_shape, U_shape)
Attempts:
2 left
💡 Hint
LU factorization of an n x n matrix produces L and U matrices of the same shape as the original matrix.
✗ Incorrect
LU factorization decomposes a square matrix A into L (lower triangular) and U (upper triangular) matrices, both having the same shape as A.
❓ data_output
intermediate2:00remaining
Number of non-zero elements after Cholesky factorization
Given a 3x3 sparse positive definite matrix, what is the number of non-zero elements in the Cholesky factor?
SciPy
import numpy as np from scipy.sparse import csc_matrix from scipy.sparse.linalg import cholesky A = csc_matrix(np.array([[4, 1, 0], [1, 3, 1], [0, 1, 2]])) ch = cholesky(A) L = ch.L() nnz = L.nnz print(nnz)
Attempts:
2 left
💡 Hint
Count the non-zero elements in the lower triangular Cholesky factor matrix.
✗ Incorrect
The Cholesky factor L is lower triangular and sparse. Counting its non-zero elements gives 5 in this case.
🔧 Debug
advanced2:00remaining
Identify the error in sparse QR factorization code
What error will this code raise when trying to perform QR factorization on a sparse matrix using scipy?
SciPy
import numpy as np from scipy.sparse import csc_matrix from scipy.sparse.linalg import qr A = csc_matrix(np.array([[1, 2], [3, 4]])) Q, R = qr(A) print(Q.toarray())
Attempts:
2 left
💡 Hint
Check if scipy.sparse.linalg has a qr function.
✗ Incorrect
scipy.sparse.linalg does not provide a qr function. Attempting to call qr from this module raises AttributeError.
🚀 Application
advanced2:00remaining
Choosing factorization for solving sparse linear systems
You have a large sparse symmetric positive definite matrix. Which factorization method is best suited for solving linear systems efficiently?
Attempts:
2 left
💡 Hint
Consider matrix properties and factorization efficiency.
✗ Incorrect
Cholesky factorization is optimized for symmetric positive definite matrices and is more efficient than LU or QR for this case.
🧠 Conceptual
expert3:00remaining
Effect of fill-in during sparse LU factorization
What does 'fill-in' mean in the context of sparse LU factorization, and why is it important?
Attempts:
2 left
💡 Hint
Think about how factorization changes the sparsity pattern.
✗ Incorrect
Fill-in occurs when zeros in the original matrix become non-zero in the factors, which can increase memory use and slow down computations.