0
0
SciPydata~10 mins

Why optimization finds best solutions in SciPy - Test Your Understanding

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

Complete the code to import the optimization function from scipy.

SciPy
from scipy.optimize import [1]
Drag options to blanks, or click blank then click option'
Afind
Boptimize
Csolve
Dminimize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'optimize' which is the module name, not a function.
Using 'solve' which is unrelated here.
Using 'find' which is not a scipy function.
2fill in blank
medium

Complete the code to define the function to minimize.

SciPy
def f(x):
    return (x - [1])**2
Drag options to blanks, or click blank then click option'
A0
B-1
C2
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 0 which shifts the minimum to zero.
Choosing 5 which moves the minimum too far.
Choosing -1 which is negative and changes the minimum location.
3fill in blank
hard

Fix the error in the optimization call by completing the missing argument.

SciPy
result = minimize(f, [1])
Drag options to blanks, or click blank then click option'
A{2}
B[2]
C(2,)
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer instead of a list.
Using a tuple which sometimes works but list is preferred.
Using a set which is unordered and invalid here.
4fill in blank
hard

Fill both blanks to print the best solution and its function value.

SciPy
print('Best x:', result.[1])
print('Minimum value:', result.[2])
Drag options to blanks, or click blank then click option'
Ax
Bfun
Csolution
Dvalue
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'solution' which is not an attribute.
Using 'value' which is not an attribute.
Confusing 'x' and 'fun' attributes.
5fill in blank
hard

Fill all three blanks to create a dictionary of squares for numbers greater than 3.

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