Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to multiply two matrices using the @ operator.
NumPy
import numpy as np A = np.array([[1, 2], [3, 4]]) B = np.array([[5, 6], [7, 8]]) result = A [1] B print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of @ for matrix multiplication.
Using + or - operators which perform addition or subtraction.
✗ Incorrect
The @ operator performs matrix multiplication in numpy.
2fill in blank
mediumComplete the code to multiply matrix A by matrix B and store the result in variable C.
NumPy
import numpy as np A = np.array([[2, 0], [1, 3]]) B = np.array([[1, 4], [2, 5]]) C = A [1] B print(C)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using * which multiplies elements individually.
Using // or ** which are not valid for matrix multiplication.
✗ Incorrect
The @ operator correctly multiplies matrices A and B.
3fill in blank
hardFix the error in the code to correctly multiply matrices A and B.
NumPy
import numpy as np A = np.array([[1, 2, 3], [4, 5, 6]]) B = np.array([[7, 8], [9, 10], [11, 12]]) result = A [1] B print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using * which causes shape mismatch error.
Using + or - which are invalid for matrix multiplication.
✗ Incorrect
The @ operator performs matrix multiplication correctly for these shapes.
4fill in blank
hardFill both blanks to create a matrix multiplication and print the shape of the result.
NumPy
import numpy as np A = np.array([[1, 0], [0, 1]]) B = np.array([[4, 1], [2, 2]]) result = A [1] B print(result[2])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of @ for multiplication.
Using .size instead of .shape to get dimensions.
✗ Incorrect
Use @ for matrix multiplication and .shape to get the dimensions of the result.
5fill in blank
hardFill all three blanks to multiply matrices and extract the element at row 1, column 0 of the result.
NumPy
import numpy as np A = np.array([[3, 5], [7, 9]]) B = np.array([[2, 4], [6, 8]]) result = A [1] B value = result[2][3] print(value)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of @ for multiplication.
Using a single bracket with comma inside for indexing.
✗ Incorrect
Use @ for matrix multiplication and [1][0] to access the element at row 1, column 0.