0
0
NumPydata~10 mins

np.min() and np.max() in NumPy - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - np.min() and np.max()
Start with array
Call np.min()
Scan all elements
Find smallest value
Return min value
Call np.max()
Scan all elements
Find largest value
Return max value
np.min() scans the array to find the smallest number and returns it. np.max() scans to find the largest number and returns it.
Execution Sample
NumPy
import numpy as np
arr = np.array([3, 7, 1, 9, 4])
min_val = np.min(arr)
max_val = np.max(arr)
print(min_val, max_val)
This code finds the smallest and largest numbers in the array and prints them.
Execution Table
StepFunction CallArray ElementsOperationResult
1np.min(arr)[3, 7, 1, 9, 4]Scan all elements to find smallest1
2np.max(arr)[3, 7, 1, 9, 4]Scan all elements to find largest9
3Print resultsmin_val=1, max_val=9Output values1 9
💡 All elements scanned; min and max values found and printed.
Variable Tracker
VariableStartAfter np.min()After np.max()Final
arr[3,7,1,9,4][3,7,1,9,4][3,7,1,9,4][3,7,1,9,4]
min_valundefined111
max_valundefinedundefined99
Key Moments - 2 Insights
Why does np.min(arr) return 1 and not the first element 3?
np.min() checks every element in the array (see execution_table step 1) and returns the smallest value found, which is 1, not just the first element.
Does np.max() change the original array?
No, np.max() only reads the array to find the largest value (execution_table step 2). It does not modify the array.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the result of np.min(arr) at step 1?
A9
B3
C1
D7
💡 Hint
Check the 'Result' column in execution_table row for step 1.
At which step does the code print the min and max values?
AStep 3
BStep 2
CStep 1
DNo print step
💡 Hint
Look for the step with 'Print results' in the 'Function Call' column.
If the array was [5, 5, 5], what would np.max(arr) return?
A0
B5
C15
DError
💡 Hint
np.max() returns the largest element; check variable_tracker for max_val.
Concept Snapshot
np.min(array) returns the smallest value in the array.
np.max(array) returns the largest value.
Both scan all elements without changing the array.
Useful to quickly find range boundaries.
Syntax: min_val = np.min(arr), max_val = np.max(arr)
Full Transcript
This lesson shows how np.min() and np.max() work by scanning an array to find the smallest and largest values. We start with an array of numbers. Calling np.min() checks each number and returns the smallest one. Calling np.max() does the same but returns the largest. The original array stays the same. We track variables min_val and max_val as they get assigned. The execution table shows each step clearly: first finding min, then max, then printing results. Common confusions include thinking np.min() returns the first element or that np.max() changes the array. The quiz tests understanding of these steps and results.