Recall & Review
beginner
What does the
@ operator do in numpy?The
@ operator performs matrix multiplication between two numpy arrays. It multiplies rows of the first matrix by columns of the second matrix and sums the products.Click to reveal answer
beginner
How is matrix multiplication different from element-wise multiplication?
Matrix multiplication combines rows and columns to produce a new matrix, while element-wise multiplication multiplies corresponding elements directly without combining rows and columns.
Click to reveal answer
intermediate
Given two matrices
A of shape (2, 3) and B of shape (3, 4), what will be the shape of A @ B?The result will have shape (2, 4) because the inner dimensions (3) match and the output shape is the outer dimensions (2 from A and 4 from B).
Click to reveal answer
intermediate
What error occurs if you try to multiply matrices with incompatible shapes using
@?You get a
ValueError saying shapes are not aligned because the number of columns in the first matrix must equal the number of rows in the second matrix.Click to reveal answer
beginner
Write a simple numpy code snippet to multiply two matrices
A and B using the @ operator.import numpy as np
A = np.array([[1, 2], [3, 4]])
B = np.array([[5, 6], [7, 8]])
result = A @ B
print(result)Click to reveal answer
What does the
@ operator do in numpy?✗ Incorrect
The
@ operator is used for matrix multiplication in numpy.If matrix A has shape (3, 2) and matrix B has shape (2, 4), what is the shape of A @ B?
✗ Incorrect
The output shape is (3, 4) because the inner dimensions 2 match and outer dimensions are 3 and 4.
What happens if you try to multiply matrices with shapes (2, 3) and (2, 4) using
@?✗ Incorrect
Matrix multiplication requires the number of columns in the first matrix to equal the number of rows in the second matrix.
Which numpy function is equivalent to using the
@ operator?✗ Incorrect
np.dot() performs matrix multiplication, same as the @ operator.What is the result of multiplying a (2, 2) identity matrix with another (2, 2) matrix using
@?✗ Incorrect
Multiplying by the identity matrix returns the other matrix unchanged.
Explain how the
@ operator works for matrix multiplication in numpy.Think about how you multiply matrices by hand.
You got /4 concepts.
Describe what happens if you try to multiply two numpy arrays with incompatible shapes using the
@ operator.Consider the rules for matrix multiplication dimensions.
You got /3 concepts.