0
0
SciPydata~10 mins

Minimizing multivariate functions (minimize) in SciPy - Interactive Code Practice

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

Complete the code to import the minimize function from scipy.optimize.

SciPy
from scipy.optimize import [1]
Drag options to blanks, or click blank then click option'
Amin
Boptimize
Cminimize
Dminimizer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'min' instead of 'minimize'.
Trying to import 'optimize' instead of 'minimize'.
2fill in blank
medium

Complete the code to define a function f(x) that returns x[0] squared plus x[1] squared.

SciPy
def f(x):
    return x[0] [1] x[0] + x[1] * x[1]
Drag options to blanks, or click blank then click option'
A*
B**
C+
D-
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '*' for squaring.
Using '**' inconsistently in the expression.
3fill in blank
hard

Fix the error in the code to minimize function f starting from initial guess [1, 1].

SciPy
result = minimize(f, [1])
Drag options to blanks, or click blank then click option'
A[1, 1]
B1, 1
C(1, 1)
D{1, 1}
Attempts:
3 left
💡 Hint
Common Mistakes
Passing separate numbers instead of a list.
Using a set instead of a list.
4fill in blank
hard

Fill both blanks to create a dictionary of squares for numbers 1 to 5, but only include numbers greater than 3.

SciPy
squares = {x: x[1]2 for x in range(1, 6) if x [2] 3}
Drag options to blanks, or click blank then click option'
A**
B%
C>
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '**' for squaring.
Using '<' instead of '>' in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only if value is positive.

SciPy
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of k.upper().
Using '<' instead of '>' in the condition.