0
0
NumPydata~10 mins

Why aggregation matters in NumPy - 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 sum of all elements in the array.

NumPy
import numpy as np
arr = np.array([1, 2, 3, 4, 5])
total = arr.[1]()
Drag options to blanks, or click blank then click option'
Asum
Bmean
Cmax
Dmin
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() instead of sum() which calculates average, not total.
Using max() or min() which find largest or smallest values, not sum.
2fill in blank
medium

Complete the code to find the average value of the array elements.

NumPy
import numpy as np
arr = np.array([10, 20, 30, 40, 50])
avg = arr.[1]()
Drag options to blanks, or click blank then click option'
Amean
Bsum
Cmedian
Dstd
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() which adds values but does not average.
Using median() which finds middle value, not average.
3fill in blank
hard

Fix the error in the code to find the maximum value in the array.

NumPy
import numpy as np
arr = np.array([3, 7, 2, 9, 5])
max_value = arr.[1]()
Drag options to blanks, or click blank then click option'
Amean
Bmin
Csum
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using min() which finds smallest value.
Using mean() or sum() which do not find max.
4fill in blank
hard

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

NumPy
words = ['data', 'is', 'fun', 'science', 'ai']
lengths = {word: [1] for word in words if len(word) [2] 3}
Drag options to blanks, or click blank then click option'
Alen(word)
B>
C<
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > which filters shorter words.
Using word instead of len(word) for length.
5fill in blank
hard

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

NumPy
data = {'a': 1, 'b': -2, 'c': 3}
result = { [1]: [2] for k, v in data.items() if v [3] 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using k instead of k.upper() for keys.
Using < instead of > for filtering values.
Using k instead of v for values.