Bird
0
0

Identify the error in this code that tries to multiply two matrices using SciPy:

medium📝 Debug Q14 of 15
SciPy - Linear Algebra (scipy.linalg)
Identify the error in this code that tries to multiply two matrices using SciPy:
import numpy as np
from scipy.linalg import dot
A = np.array([[1, 0], [0, 1]])
B = np.array([[4, 1], [2, 2]])
C = dot(A, B)
print(C)
AThe print statement is missing parentheses
BMatrix A is not square
CThe function dot is not in scipy.linalg, it is in numpy
DMatrix B has wrong dimensions
Step-by-Step Solution
Solution:
  1. Step 1: Check the dot function location

    The dot function for matrix multiplication is in numpy, not scipy.linalg.
  2. Step 2: Understand the error cause

    Importing dot from scipy.linalg causes an ImportError or AttributeError.
  3. Final Answer:

    The function dot is not in scipy.linalg, it is in numpy -> Option C
  4. Quick Check:

    Use numpy.dot for matrix multiplication [OK]
Quick Trick: Use numpy.dot, not scipy.linalg.dot [OK]
Common Mistakes:
MISTAKES
  • Assuming dot is in scipy.linalg
  • Ignoring correct import sources
  • Confusing matrix dimensions as error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes