Bird
0
0

Which of the following is the correct way to specify integer variables in scipy.optimize.linprog?

easy📝 Syntax Q12 of 15
SciPy - Advanced Optimization

Which of the following is the correct way to specify integer variables in scipy.optimize.linprog?

from scipy.optimize import linprog

result = linprog(c, A_ub=A, b_ub=b, integrality=...)
Aintegrality=True # boolean for all integer
Bintegrality=[1, 0, 1] # 1 means integer, 0 means continuous
Cintegrality='integer' # string to specify all integer
Dintegrality=None # default no integer constraints
Step-by-Step Solution
Solution:
  1. Step 1: Recall integrality parameter usage

    The integrality argument takes a list or array indicating which variables are integers (1) or continuous (0).
  2. Step 2: Check options

    integrality=[1, 0, 1] # 1 means integer, 0 means continuous correctly uses a list with 1s and 0s. Options A, B, and D use incorrect types.
  3. Final Answer:

    integrality=[1, 0, 1] # 1 means integer, 0 means continuous -> Option B
  4. Quick Check:

    integrality list = integer flags [OK]
Quick Trick: Use list of 1/0 to mark integer variables [OK]
Common Mistakes:
  • Passing a string or boolean instead of list
  • Leaving integrality as None to expect integers
  • Confusing integrality with other parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes