0
0
NumPydata~10 mins

Matrix multiplication with @ operator in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A*
B+
C-
D@
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of @ for matrix multiplication.
Using + or - operators which perform addition or subtraction.
2fill in blank
medium

Complete 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'
A//
B**
C@
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using * which multiplies elements individually.
Using // or ** which are not valid for matrix multiplication.
3fill in blank
hard

Fix 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'
A-
B@
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using * which causes shape mismatch error.
Using + or - which are invalid for matrix multiplication.
4fill in blank
hard

Fill 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'
A@
B*
C.shape
D.size
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of @ for multiplication.
Using .size instead of .shape to get dimensions.
5fill in blank
hard

Fill 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'
A@
B[1, 0]
D[1][0]
Attempts:
3 left
💡 Hint
Common Mistakes
Using * instead of @ for multiplication.
Using a single bracket with comma inside for indexing.