0
0
SciPydata~10 mins

Singular Value Decomposition (svd) 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 SVD function from scipy.

SciPy
from scipy.linalg import [1]
Drag options to blanks, or click blank then click option'
Asvd
Beig
Cinv
Ddet
Attempts:
3 left
💡 Hint
Common Mistakes
Importing eigenvalue functions like eig instead of svd.
Trying to import from the wrong module.
2fill in blank
medium

Complete the code to perform SVD on matrix A.

SciPy
U, s, VT = [1](A)
Drag options to blanks, or click blank then click option'
Aeig
Binv
Csvd
Ddot
Attempts:
3 left
💡 Hint
Common Mistakes
Using eigenvalue decomposition function eig instead of svd.
Trying to invert the matrix instead of decomposing.
3fill in blank
hard

Fix the error in the code to reconstruct matrix A from SVD components.

SciPy
A_reconstructed = U @ [1] @ VT
Drag options to blanks, or click blank then click option'
Anp.diag(s)
Bs
Cnp.dot(s)
Dnp.sum(s)
Attempts:
3 left
💡 Hint
Common Mistakes
Using s directly without converting to diagonal matrix.
Using np.dot(s) which is incorrect syntax.
Summing singular values instead of creating a diagonal matrix.
4fill in blank
hard

Fill both blanks to create a reduced SVD keeping only the top 2 singular values.

SciPy
U_reduced = U[:, :[1]]
s_reduced = np.diag(s[:[2]])
Drag options to blanks, or click blank then click option'
A2
B3
C1
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong slice indices like 3 or 1.
Not converting singular values to diagonal matrix.
5fill in blank
hard

Fill all three blanks to reconstruct matrix A using reduced SVD components.

SciPy
A_approx = U_reduced @ [1] @ [2][:[3], :]
Drag options to blanks, or click blank then click option'
As_reduced
BVT
C2
DU
Attempts:
3 left
💡 Hint
Common Mistakes
Using full VT instead of sliced.
Using wrong slicing index.
Using U instead of VT in multiplication.