Challenge - 5 Problems
Matrix Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this matrix multiplication?
Given two numpy arrays A and B, what is the result of A @ B?
NumPy
import numpy as np A = np.array([[1, 2], [3, 4]]) B = np.array([[2, 0], [1, 2]]) result = A @ B print(result)
Attempts:
2 left
💡 Hint
Remember matrix multiplication sums the products of rows of A with columns of B.
✗ Incorrect
Matrix multiplication with @ multiplies rows of A by columns of B and sums the products. For example, element (0,0) is 1*2 + 2*1 = 4.
❓ data_output
intermediate1:30remaining
What is the shape of the result after matrix multiplication?
If A has shape (3, 4) and B has shape (4, 2), what is the shape of A @ B?
NumPy
import numpy as np A = np.zeros((3,4)) B = np.zeros((4,2)) result = A @ B print(result.shape)
Attempts:
2 left
💡 Hint
The resulting matrix shape is rows of A by columns of B.
✗ Incorrect
Matrix multiplication results in a matrix with the number of rows of the first matrix and the number of columns of the second matrix.
🔧 Debug
advanced2:00remaining
Why does this matrix multiplication raise an error?
What error will this code raise and why?
NumPy
import numpy as np A = np.array([[1, 2, 3], [4, 5, 6]]) B = np.array([[7, 8], [9, 10]]) result = A @ B
Attempts:
2 left
💡 Hint
Check if the inner dimensions of the matrices match for multiplication.
✗ Incorrect
Matrix multiplication requires the number of columns in A to equal the number of rows in B. Here, A has 3 columns but B has 2 rows, so it raises a ValueError.
🚀 Application
advanced2:30remaining
Calculate the product of a matrix and its transpose
Given matrix M, what is the result of M @ M.T?
NumPy
import numpy as np M = np.array([[1, 2], [3, 4], [5, 6]]) result = M @ M.T print(result)
Attempts:
2 left
💡 Hint
Multiplying a matrix by its transpose results in a symmetric matrix with dot products of rows.
✗ Incorrect
M @ M.T computes dot products of rows of M with each other, resulting in a symmetric matrix with shape (3,3).
🧠 Conceptual
expert1:30remaining
Which statement about the @ operator in numpy is TRUE?
Select the correct statement about the @ operator for numpy arrays.
Attempts:
2 left
💡 Hint
Think about how matrix multiplication works and what the @ operator does.
✗ Incorrect
The @ operator performs matrix multiplication, which requires the number of columns in the first array to match the number of rows in the second array.