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.
Not using the alias np.
✗ Incorrect
We import the numpy library as np to use its functions easily.
2fill in blank
mediumComplete the code to create a 2x2 numpy array named matrix.
NumPy
matrix = 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.
Creating a matrix with wrong dimensions.
✗ Incorrect
The matrix must be a 2x2 nested list to create a 2D numpy array.
3fill in blank
hardFix the error in the code to compute the inverse of the matrix.
NumPy
inverse = np.linalg.[1](matrix) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using
det which computes determinant, not inverse.Using
solve which solves linear systems.✗ Incorrect
The function np.linalg.inv() computes the inverse of a matrix.
4fill in blank
hardFill both blanks to create a dictionary with keys as matrix elements and values as their inverses.
NumPy
inverse_dict = {element: [1] for row in matrix for element in row if element [2] 0} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality check instead of inequality in the condition.
Not handling zero elements causing division by zero.
✗ Incorrect
We calculate the inverse of each element by dividing 1 by it, and skip zero elements to avoid division errors.
5fill in blank
hardFill all three blanks to compute the inverse matrix and print it.
NumPy
import numpy as np matrix = np.array([1]) inverse = np.linalg.[2](matrix) print([3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong matrix shape.
Calling a wrong function instead of
inv.Printing the original matrix instead of the inverse.
✗ Incorrect
We create a 2x2 matrix, compute its inverse using np.linalg.inv(), and print the inverse matrix.