0
0
NumPydata~10 mins

Why NumPy performance 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 create a NumPy array from a Python list.

NumPy
import numpy as np
arr = np.[1]([1, 2, 3, 4, 5])
Drag options to blanks, or click blank then click option'
Amatrix
Bseries
Clist
Darray
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'list' instead of 'array' which is not a NumPy function.
Using 'matrix' which is a different NumPy type.
Using 'series' which belongs to pandas, not NumPy.
2fill in blank
medium

Complete the code to calculate the mean of a NumPy array.

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

Fix the error in the code to multiply two NumPy arrays element-wise.

NumPy
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
result = arr1 [1] arr2
Drag options to blanks, or click blank then click option'
A-
B+
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' which adds elements instead of multiplying.
Using '-' which subtracts elements.
Using '/' which divides elements.
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 3 letters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog']
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 selects shorter words.
Using 'word' as value instead of length.
Not filtering words by length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase words as keys and their lengths as values, only for words longer than 3 letters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog']
result = { [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 'word' instead of 'word.upper()' for keys.
Using '<' instead of '>' in the condition.
Using 'word' instead of 'len(word)' for values.