Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a NumPy array from a list.
Pandas
import numpy as np arr = np.[1]([1, 2, 3, 4]) print(arr)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pandas functions like DataFrame or Series instead of NumPy array.
Trying to use list() which is a Python built-in, not NumPy.
✗ Incorrect
Use np.array() to create a NumPy array from a list.
2fill in blank
mediumComplete the code to calculate the mean of a NumPy array.
Pandas
import numpy as np arr = np.array([10, 20, 30, 40]) mean_value = arr.[1]() print(mean_value)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using sum() which adds all elements but does not calculate average.
Using median() which finds the middle value, not the average.
✗ Incorrect
Use mean() method on a NumPy array to calculate the average value.
3fill in blank
hardFix the error in the code to create a NumPy array of zeros with length 5.
Pandas
import numpy as np zeros = np.[1](5) print(zeros)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'zeroes' which is a common misspelling.
Using 'empty' which creates an uninitialized array, not zeros.
✗ Incorrect
The correct function to create an array of zeros is np.zeros().
4fill in blank
hardFill both blanks to create a NumPy array and calculate its standard deviation.
Pandas
import numpy as np arr = np.[1]([2, 4, 6, 8]) std_dev = arr.[2]() print(std_dev)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() instead of std() for standard deviation.
Using sum() which adds elements but does not calculate deviation.
✗ Incorrect
Use np.array() to create the array and std() to find standard deviation.
5fill in blank
hardFill all three blanks to create a NumPy array, filter values greater than 3, and calculate their sum.
Pandas
import numpy as np arr = np.[1]([1, 2, 3, 4, 5]) filtered = arr[arr [2] 3] result = filtered.[3]() print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > for filtering.
Using mean() instead of sum() for the final calculation.
✗ Incorrect
Create the array with np.array(), filter with >, and sum with sum().