0
0
SciPydata~10 mins

Minimizing scalar functions (minimize_scalar) 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 function for minimizing scalar functions.

SciPy
from scipy.optimize import [1]
Drag options to blanks, or click blank then click option'
Aminimize_scalar
Bminimize_vector
Cminimize_matrix
Dminimize_function
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to import a non-existent function like minimize_vector.
Confusing minimize_scalar with minimize_function.
2fill in blank
medium

Complete the code to define a simple quadratic function to minimize.

SciPy
def f(x):
    return (x - [1]) ** 2
Drag options to blanks, or click blank then click option'
A3
B0
C5
D-2
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 0 or negative numbers which change the minimum location.
Using a number not matching the intended minimum.
3fill in blank
hard

Fix the error in the code to minimize the function f using minimize_scalar.

SciPy
result = [1](f)
print(result.x)
Drag options to blanks, or click blank then click option'
Aminimize_vector
Bminimize_matrix
Cminimize_scalar
Dminimize_function
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent function like minimize_vector.
Misspelling the function name.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps numbers to their squares for numbers greater than 2.

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

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths for words longer than 3 characters.

SciPy
result = {{ { [1] } : [2] for word in words if len(word) [3] 3}}
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the key instead of uppercase.
Using '<' instead of '>' in the condition.