.amax()
Published Jun 19, 2023Updated May 15, 2024
Contribute to Docs
The .amax()
function returns the maximum value of a given array or the maximum along an axis. The .amax()
function is equivalent to the NumPy method ndarray.max()
.
Syntax
numpy.amax(a, axis, out, keepdims, initial, where)
The a
parameter is required and represents the array of elements to choose the maximum from. All other parameters are optional.
Parameters of the .amax()
function:
a
: (Input) The array of elements to choose the maximum from.axis
: (Default = None) An integer or a tuple of integers specifying the axis/axes along which to operate. If a tuple of integers, the maximum is across multiple axes.out
: (Default = None) Anndarray
to receive result. Must have the same shape as the expected output.keepdims
: (Default =initial
: (Default =where
: (Default =
Returns:
- If
axis
is None, the result would be a scalar value. - If
axis
is an integer, the result would be an array of dimensionsa.ndim - 1
. - If
axis
is a tuple, the result would be an array of dimensionsa.ndim - len(axis)
.
Example
The following example creates an array, applies several .amax()
operations, and returns each result to the console.
import numpy as npnd = np.array([[2,4,6,8],[10,12,14,16]])print(np.amax(nd))print(np.amax(nd, axis=0))print(np.amax(nd, axis=1))
This produces the following output:
16[10 12 14 16][ 8 16]
Codebyte Example
The following example creates a 2-dimensional array composed of random integers (between 1 and 20). The code prints the array and then prints the result of four .amax()
operations that use different arguments.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.