0
0
NumPydata~10 mins

np.argmin() and np.argmax() in NumPy - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to find the index of the smallest value in the array.

NumPy
import numpy as np
arr = np.array([3, 1, 4, 1, 5])
index_min = np.[1](arr)
print(index_min)
Drag options to blanks, or click blank then click option'
Amin
Bargmax
Cargmin
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.min() which returns the minimum value, not the index.
Using np.argmax() which finds the index of the maximum value.
2fill in blank
medium

Complete the code to find the index of the largest value in the array.

NumPy
import numpy as np
arr = np.array([10, 20, 30, 20, 10])
index_max = np.[1](arr)
print(index_max)
Drag options to blanks, or click blank then click option'
Aargmax
Bargmin
Cmin
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.max() which returns the maximum value, not the index.
Using np.argmin() which finds the index of the minimum value.
3fill in blank
hard

Fix the error in the code to correctly find the index of the smallest value.

NumPy
import numpy as np
arr = np.array([7, 2, 5, 3])
index = np.argmin[1](arr)
print(index)
Drag options to blanks, or click blank then click option'
A<
B(
C{
D[
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets instead of parentheses for function calls.
Missing the opening parenthesis.
4fill in blank
hard

Fill both blanks to create a dictionary of indices of min and max values from the array.

NumPy
import numpy as np
arr = np.array([8, 6, 7, 5, 3, 0, 9])
result = {'min_index': np.[1](arr), 'max_index': np.[2](arr)}
print(result)
Drag options to blanks, or click blank then click option'
Aargmin
Bmin
Cargmax
Dmax
Attempts:
3 left
💡 Hint
Common Mistakes
Using np.min() or np.max() which return values, not indices.
Mixing up argmin and argmax.
5fill in blank
hard

Fill both blanks to create a dictionary with keys as uppercase words and values as their indices if the index is greater than 2.

NumPy
words = ['apple', 'banana', 'cherry', 'date', 'fig']
result = {word[1]: i for i, word in enumerate(words) if i [2] 2}
print(result)
Drag options to blanks, or click blank then click option'
A.upper()
C>
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to call the upper() method with parentheses.
Using the wrong comparison operator in the if condition.
Trying to modify the index value unnecessarily.