Bird
0
0

Examine the following code:

medium📝 Debug Q6 of 15
SciPy - Advanced Optimization
Examine the following code:
from scipy.optimize import dual_annealing

def f(x):
    return x[0] + x[1]

result = dual_annealing(f, bounds=[(0, 1)])
print(result.fun)

What is the issue here?
AThe function is not defined properly
BBounds length does not match the function input dimension
Cdual_annealing requires integer bounds only
DMissing import statement for numpy
Step-by-Step Solution
Solution:
  1. Step 1: Analyze function input

    The function f expects a 2-dimensional input x[0] and x[1].
  2. Step 2: Check bounds

    The bounds provided are for only one variable: [(0,1)].
  3. Step 3: Identify mismatch

    Number of bounds must match the dimension of the input vector.
  4. Final Answer:

    Bounds length does not match the function input dimension -> Option B
  5. Quick Check:

    Bounds length vs input dimension [OK]
Quick Trick: Bounds must match function input dimension [OK]
Common Mistakes:
  • Providing fewer bounds than input dimensions
  • Assuming function input is scalar when vector expected

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes