Python:NumPy .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) Anndarrayto receive result. Must have the same shape as the expected output.keepdims: (Default =initial: (Default =where: (Default =
Returns:
- If
axisis None, the result would be a scalar value. - If
axisis an integer, the result would be an array of dimensionsa.ndim - 1. - If
axisis 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.
Learn Python:NumPy on Codecademy
- Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
- Includes 27 Courses
- With Professional Certification
- Beginner Friendly.95 hours
- Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.
- With Certificate
- Beginner Friendly.24 hours