0
0
NumPydata~5 mins

np.min() and np.max() in NumPy - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does np.min() do in numpy?

np.min() finds the smallest value in an array or along a specified axis.

Click to reveal answer
beginner
What is the purpose of np.max()?

np.max() returns the largest value in an array or along a specified axis.

Click to reveal answer
intermediate
How do you find the minimum value in each column of a 2D numpy array?

Use np.min(array, axis=0). Axis 0 means down the rows, so it finds min per column.

Click to reveal answer
intermediate
How to find the maximum value in each row of a 2D numpy array?

Use np.max(array, axis=1). Axis 1 means across columns, so it finds max per row.

Click to reveal answer
advanced
What happens if you call np.min() or np.max() on an empty array?

It raises a ValueError because there is no data to find min or max.

Click to reveal answer
What does np.min() return when used on a numpy array?
AThe average value of the array
BThe largest value in the array
CThe smallest value in the array
DThe sum of all values in the array
How do you find the maximum value in each row of a 2D numpy array named arr?
A<code>np.max(arr, axis=1)</code>
B<code>np.min(arr, axis=1)</code>
C<code>np.max(arr, axis=0)</code>
D<code>np.min(arr, axis=0)</code>
What will np.min() do if the array is empty?
AReturn 0
BRaise a ValueError
CReturn infinity
DReturn None
Which axis should you use with np.min() to find the minimum value in each column of a 2D array?
Aaxis=0
Baxis=1
Caxis=2
Daxis=None
If you want the overall maximum value in a numpy array, which function call is correct?
A<code>array.min(axis=0)</code>
B<code>np.min(array)</code>
C<code>array.max(axis=1)</code>
D<code>np.max(array)</code>
Explain how to use np.min() and np.max() to find minimum and maximum values along different axes in a 2D numpy array.
Think about rows and columns as directions to find min or max.
You got /4 concepts.
    What error occurs if you try to find the minimum or maximum of an empty numpy array using np.min() or np.max()? Why?
    Consider what happens when there is nothing to compare.
    You got /3 concepts.