0
0
NumPydata~10 mins

NumPy with 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 SciPy stats module.

NumPy
from scipy import [1]

print(stats.norm.cdf(0))
Drag options to blanks, or click blank then click option'
Aoptimize
Bstats
Cintegrate
Dlinalg
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong SciPy submodule like optimize or integrate.
Trying to use stats without importing it.
2fill in blank
medium

Complete the code to create a NumPy array of 5 random numbers from a normal distribution using SciPy.

NumPy
import numpy as np
from scipy import stats

random_nums = stats.norm.[1](size=5)
print(random_nums)
Drag options to blanks, or click blank then click option'
Arvs
Bppf
Ccdf
Dpdf
Attempts:
3 left
💡 Hint
Common Mistakes
Using cdf or pdf which compute probabilities, not samples.
Using ppf which is the percent point function (inverse cdf).
3fill in blank
hard

Fix the error in the code to calculate the mean of a NumPy array.

NumPy
import numpy as np

arr = np.array([1, 2, 3, 4, 5])
mean_value = arr.[1]()
print(mean_value)
Drag options to blanks, or click blank then click option'
Amean
Baverage
Cmedian
Dmode
Attempts:
3 left
💡 Hint
Common Mistakes
Using average() which is a NumPy function but not an array method.
Confusing mean with median or mode.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

NumPy
words = ['data', 'science', 'is', 'fun']
lengths = {word: [1] for word in words if len(word) [2] 3}
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Using the wrong comparison operator like <= instead of >.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 2 characters.

NumPy
words = ['apple', 'to', 'banana', 'go']
result = { [1]: [2] for w in words if len(w) [3] 2 }
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
C>
Dw
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word instead of uppercase for keys.
Using wrong comparison operator or value for filtering.