0
0
SciPydata~10 mins

Linear programming (linprog) 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 linear programming function from scipy.

SciPy
from scipy.optimize import [1]

result = linprog(c=[-1, 4], A_ub=[[2, 1], [1, 2]], b_ub=[20, 20])
Drag options to blanks, or click blank then click option'
Alinopt
Bminimize
Clinprog
Doptimize
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'minimize' instead of 'linprog'.
Trying to import from a wrong module.
2fill in blank
medium

Complete the code to define the objective function coefficients for minimization.

SciPy
c = [1]

result = linprog(c, A_ub=[[1, 2], [3, 1]], b_ub=[4, 3])
Drag options to blanks, or click blank then click option'
A[1, 2]
B[0, 0]
C[2, 3]
D[-1, 4]
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive coefficients when the problem requires minimization of negative values.
Using zeros which do not represent the objective.
3fill in blank
hard

Fix the error in the code by completing the missing inequality matrix.

SciPy
A_ub = [1]

result = linprog(c=[-1, 4], A_ub=A_ub, b_ub=[20, 20])
Drag options to blanks, or click blank then click option'
A[[1, 2], [3, 1]]
B[[2, 1], [1, 2]]
C[[1, 1], [2, 2]]
D[[0, 1], [1, 0]]
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect matrices that do not match the constraints.
Confusing A_ub with A_eq.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths if length is greater than 3.

SciPy
words = ['data', 'ai', 'science', 'ml']
lengths = { [1] : [2] for word in words if len(word) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Cword.upper()
Dlen
Attempts:
3 left
💡 Hint
Common Mistakes
Using the length as key and word as value.
Using functions instead of values.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 3.

SciPy
words = ['data', 'ai', 'science', 'ml']
lengths = { [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 lowercase words as keys.
Using incorrect comparison operators.