Bird
0
0

What is the error in this code snippet?

medium📝 Debug Q6 of 15
SciPy - Advanced Optimization

What is the error in this code snippet?

from scipy.optimize import milp

c = [2, 3]
integrality = [1, 0, 1]

result = milp(c, integrality=integrality)
print(result.x)
AUsing milp instead of linprog
BObjective vector c contains negative values
CMissing bounds parameter for variables
DLength of integrality list does not match number of variables
Step-by-Step Solution
Solution:
  1. Step 1: Check dimensions

    Objective vector c has length 2, integrality list length 3.
  2. Step 2: Understand integrality parameter

    Integrality must have same length as number of variables to specify integer constraints correctly.
  3. Step 3: Identify error

    Mismatch causes error in milp call.
  4. Final Answer:

    Length of integrality list does not match number of variables -> Option D
  5. Quick Check:

    Check parameter lengths [OK]
Quick Trick: Ensure integrality length matches variables [OK]
Common Mistakes:
  • Mismatching integrality and variable counts
  • Assuming default bounds without specifying
  • Confusing milp with linprog usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes