Python:NumPy .amin()

THE-Spellchecker's avatar
Published Jun 1, 2023Updated May 15, 2024

The .amin() function returns the minimum of an array or minimum along an axis. The .amin() function is equivalent to ndarray.min().

  • 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

Syntax

numpy.amin(a, axis, out, keepdims, initial, where)

The a parameter is required and represents the array of elements to choose the minimum from. All other parameters are optional.

Parameters of the .amin() function:

  • a: The array of elements to choose the minimum from.
  • axis: An int or a tuple of ints specifying the axis/axes along which to choose the minimum. By default it is set as axis=None.
  • out: An ndarray to receive result. Must have the same shape as expected output.
  • keepdims: A boolean; if True will keep reduced axes in the result as dimensions with size one.
  • initial: The maximum value of an output element.
  • where: A boolean array that maps to array and selects which elements to compare for the minimum.

Returns:

  • If axis is None, the result would be a scalar value of the minimum element of the array.
  • If axis is an integer, the result would be an array of dimension a.ndim - 1.
  • If axis is a tuple, the result would be an array of dimension a.ndim - len(axis).

Example

The following example creates an array then uses a few .amin() operations to return the minimum.

import numpy as np
nd = np.array([[1,2,3],[4,5,6]])
print(np.amin(nd))
print(np.amin(nd, axis=0))
print(np.amin(nd, axis=1))

This produces the following output:

1
[1 2 3]
[1 4]

Codebyte Example

The following example creates an array then uses a few .amin() operations with various arguments to return the minimum.

Code
Output

All contributors

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