0
0
NumPydata~10 mins

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

NumPy
import numpy as np

numbers = [1, 2, 3, 4, 5]
array = np.[1](numbers)
print(array)
Drag options to blanks, or click blank then click option'
Aarray
Blist
Carrayify
Dtoarray
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.list() instead of np.array()
Trying to use np.arrayify() which does not exist
2fill in blank
medium

Complete the code to add 5 to every element in the NumPy array.

NumPy
import numpy as np

arr = np.array([10, 20, 30])
result = arr [1] 5
print(result)
Drag options to blanks, or click blank then click option'
A-
B/
C+
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using * which multiplies instead of adds
Using / which divides instead of adds
3fill in blank
hard

Fix the error in the code to compute the mean of the array elements.

NumPy
import numpy as np

arr = np.array([2, 4, 6, 8])
mean_value = arr.[1]()
print(mean_value)
Drag options to blanks, or click blank then click option'
Amean
Bavg
Cmedian
Daverage
Attempts:
3 left
💡 Hint
Common Mistakes
Using arr.average() which is not a NumPy method
Using arr.avg() which does not exist
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 = ['cat', 'elephant', 'dog', 'giraffe']
lengths = {word: [1] for word in words if [2]
print(lengths)
Drag options to blanks, or click blank then click option'
Alen(word)
Bword > 3
Clen(word) > 3
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'word > 3' which compares string to number
Using 'word' instead of length in the dictionary values
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 4 letters.

NumPy
words = ['apple', 'bat', 'carrot', 'dog']
result = { [1]: [2] for w in words if [3] }
print(result)
Drag options to blanks, or click blank then click option'
Aw.upper()
Blen(w)
Clen(w) > 4
Dw.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using w.lower() instead of w.upper() for keys
Not filtering words by length
Using w instead of len(w) for values