0
0
NumPydata~10 mins

Why statistics with NumPy matters - Test Your Understanding

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

Complete the code to calculate the mean of the data array using NumPy.

NumPy
import numpy as np

data = np.array([10, 20, 30, 40, 50])
mean_value = np.[1](data)
print(mean_value)
Drag options to blanks, or click blank then click option'
Amax
Bmedian
Csum
Dmean
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum instead of mean will give the total, not the average.
Using median calculates the middle value, not the average.
2fill in blank
medium

Complete the code to calculate the standard deviation of the data array using NumPy.

NumPy
import numpy as np

data = np.array([5, 10, 15, 20, 25])
std_dev = np.[1](data)
print(std_dev)
Drag options to blanks, or click blank then click option'
Asum
Bstd
Cmean
Dvar
Attempts:
3 left
💡 Hint
Common Mistakes
Using var calculates variance, not standard deviation.
Using mean calculates average, not spread.
3fill in blank
hard

Fix the error in the code to calculate the median of the data array using NumPy.

NumPy
import numpy as np

data = np.array([3, 1, 4, 1, 5])
median_value = np.[1](data)
print(median_value)
Drag options to blanks, or click blank then click option'
Amedian
Bmean
Cmode
Dstd
Attempts:
3 left
💡 Hint
Common Mistakes
Using mode is not available in NumPy and causes an error.
Using mean calculates average, not the middle value.
4fill in blank
hard

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

NumPy
words = ['apple', 'bat', 'carrot', 'dog', 'elephant']
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)
B==
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using == filters only words with length exactly 3.
Using <= includes words with length 3 or less.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 10.

NumPy
data = {'a': 5, 'b': 15, 'c': 25}
result = { [1]: [2] for k, v in data.items() if v [3] 10 }
print(result)
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() does not change keys to uppercase.
Using < or == filters wrong values.