0
0
SciPydata~10 mins

Simpson's rule (simpson) 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 Simpson's rule function from scipy.integrate.

SciPy
from scipy.integrate import [1]
Drag options to blanks, or click blank then click option'
Asimpson
Bquad
Cromb
Dtrapz
Attempts:
3 left
💡 Hint
Common Mistakes
Importing trapz instead of simpson.
Using quad which is for adaptive quadrature, not Simpson's rule.
2fill in blank
medium

Complete the code to calculate the integral of y over x using Simpson's rule.

SciPy
result = simpson(y, [1])
Drag options to blanks, or click blank then click option'
Arange
Bdx
Caxis
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Passing dx instead of x array.
Using axis which is a keyword argument, not positional here.
3fill in blank
hard

Fix the error in the code to correctly compute the integral with simpson when y is a 2D array along axis 0.

SciPy
integral = simpson(y, x, axis=[1])
Drag options to blanks, or click blank then click option'
A1
B-1
C0
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using axis=1 which integrates along columns instead.
Using axis=-1 which is last axis, not axis 0.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

SciPy
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using word instead of len(word) for the value.
Using word > 3 which compares string to int.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase words to their values only if the value is positive.

SciPy
result = [1]: [2] for [3] in data.items() if [2] > 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck, v
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using item instead of k, v in the loop.
Not converting keys to uppercase.