Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to find the minimum value in the array.
NumPy
import numpy as np arr = np.array([3, 7, 1, 9, 5]) min_value = np.[1](arr) print(min_value)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.max() instead of np.min()
Trying to use Python's built-in min() without numpy
✗ Incorrect
The np.min() function returns the smallest value in the array.
2fill in blank
mediumComplete the code to find the maximum value in the 2D array.
NumPy
import numpy as np arr = np.array([[4, 2, 8], [1, 7, 5]]) max_value = np.[1](arr) print(max_value)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.min() instead of np.max()
Trying to use Python's built-in max() without numpy
✗ Incorrect
The np.max() function returns the largest value in the array.
3fill in blank
hardFix the error in the code to correctly find the minimum value along axis 0.
NumPy
import numpy as np arr = np.array([[10, 20], [5, 15]]) min_values = np.min(arr, [1]=0) print(min_values)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'axes' instead of 'axis'
Using 'dim' or 'direction' which are invalid parameters
✗ Incorrect
The correct parameter name to specify the axis is axis.
4fill in blank
hardFill both blanks to create a dictionary of max values for each column in the array.
NumPy
import numpy as np arr = np.array([[3, 6, 9], [2, 8, 5]]) max_dict = {i: np.[1](arr, [2]=0)[i] for i in range(arr.shape[1])} print(max_dict)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.min() instead of np.max()
Using 'dim' instead of 'axis' as parameter
✗ Incorrect
Use np.max() to find max values and axis to specify the dimension.
5fill in blank
hardFill all three blanks to create a dictionary of min values for each row in the array.
NumPy
import numpy as np arr = np.array([[7, 4, 1], [3, 9, 6]]) min_dict = {i: np.[1](arr, [2]=1)[[3]] for i in range(arr.shape[0])} print(min_dict)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.max() instead of np.min()
Using wrong parameter name instead of 'axis'
Using a fixed number instead of the loop variable
✗ Incorrect
Use np.min() to find minimum values, axis to specify dimension, and i as the axis index.