0
0
NumPydata~10 mins

np.linalg.solve() for linear systems in NumPy - 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 numpy library with the common alias.

NumPy
import [1] as np
Drag options to blanks, or click blank then click option'
Amatplotlib
Bpandas
Cnumpy
Dscipy
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like pandas or matplotlib.
Forgetting to use the alias 'np'.
2fill in blank
medium

Complete the code to define matrix A as a 2x2 numpy array.

NumPy
A = np.array([1])
Drag options to blanks, or click blank then click option'
A[3, 1, 1, 2]
B[[3 1], [1 2]]
C[[3, 1, 1], [2]]
D[[3, 1], [1, 2]]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a flat list instead of nested lists.
Missing commas between elements.
3fill in blank
hard

Fix the error in the code to solve the system Ax = b using numpy.

NumPy
x = np.linalg.[1](A, b)
Drag options to blanks, or click blank then click option'
Asolve
Bdet
Cinv
Ddot
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.linalg.inv() and then multiplying, which is less efficient.
Using np.dot() which only does matrix multiplication.
4fill in blank
hard

Fill both blanks to create vector b and solve the system Ax = b.

NumPy
b = np.array([1])
x = np.linalg.solve(A, [2])
Drag options to blanks, or click blank then click option'
A[9, 8]
Bb
C[[9], [8]]
DA
Attempts:
3 left
💡 Hint
Common Mistakes
Using a 2D array for b which may cause shape errors.
Passing A instead of b to solve.
5fill in blank
hard

Fill all three blanks to create matrix A, vector b, and solve for x.

NumPy
A = np.array([1])
b = np.array([2])
x = np.linalg.solve([3], b)
Drag options to blanks, or click blank then click option'
A[[4, 2], [3, 1]]
B[7, 5]
CA
D[[7], [5]]
Attempts:
3 left
💡 Hint
Common Mistakes
Passing b instead of A as the first argument to solve.
Using 2D array for b which is unnecessary here.