Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong library like pandas or matplotlib.
Forgetting to use the alias 'np'.
✗ Incorrect
The numpy library is commonly imported as np to use its functions easily.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a flat list instead of nested lists.
Missing commas between elements.
✗ Incorrect
Matrix A must be a 2x2 list of lists to create a 2D numpy array.
3fill in blank
hardFix 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'
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.
✗ Incorrect
The function np.linalg.solve() solves the linear system Ax = b directly.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a 2D array for b which may cause shape errors.
Passing A instead of b to solve.
✗ Incorrect
Vector b is a 1D numpy array with values [9, 8]. Then we pass b to np.linalg.solve().
5fill in blank
hardFill 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'
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.
✗ Incorrect
Matrix A and vector b are defined as numpy arrays. Then np.linalg.solve() uses A and b to find x.