Signup/Sign In
LAST UPDATED: DECEMBER 12, 2020

NumPy amin() Function

In this tutorial, we will cover the numpy.amin() function of Numpy library.

This is a statistical function of the NumPy library that is used to return the minimum element of an array or minimum element along an axis.

Syntax of numpy.amin():

The syntax required to use this function is as follows:

numpy.amin(a, axis, out, keepdims=<no value>, initial=<no value>, where=<no value>)

Parameters:

Now it's time to discuss the parameters of this method:

  • a
    This parameter indicates the input data that is in the form of an array.

  • axis
    It is an optional parameter indicating the Axis or axes along which to operate. The value of this parameter can be int or a tuple of int values and also has default value as None.

  • out
    This optional parameter is used to indicate an alternative output array in which the result gets stored. The value of this parameter is in the form of an ndarray.

  • keepdims
    With the help of this optional parameter(having boolean value), the result will broadcast correctly against the input array. If this option is set to True, the axes which are reduced are left in the result as dimensions with size one.

  • initial
    This is a scalar and optional parameter used to indicate the maximum value of an output element.

  • where
    This is an optional parameter used to indicate the elements to compare for the minimum value

Returned Values:

This function is used to return the minimum value of any given array. If the axis is None, the result will be a scalar value. If the axis is given, the result is an array of dimension a.ndim - 1.

Example 1: Basic example

We will now cover a basic example using this function:

import numpy as np  

a = np.array([[2,15,20],[80,43,31],[22,43,10]])  
print("The original array:\n")  
print(a)  

print("\nThe minimum element among the array:",np.amin(a))  
print("\nThe minimum element among the rows of array",np.amin(a,0))  
print("\nThe minimum element among the columns of array",np.amin(a,1))  


The original array:

[[ 2 15 20]
[80 43 31]
[22 43 10]]

The minimum element among the array: 2
The minimum element among the rows of array [ 2 15 10]
The minimum element among the columns of array [ 2 31 10]

Example 2:

Another code example is as follows:

a = np.arange(9).reshape((3,3))

print("The Array is :")
print(a)

print("Minimum element in the array is:",np.amin(a))         

print("Minimum element along the first axis of array is:",np.amin(a, axis=0))  

print("Minimum element along the second axis of array is:",np.amin(a, axis=1))


The Array is :
[[0 1 2]
[3 4 5]
[6 7 8]]
Minimum element in the array is: 0
Minimum element along the first axis of array is: [0 1 2]
Minimum element along the second axis of array is: [0 3 6]

np.amin(a, where=[False, True], initial=10, axis=0)


array([10, 1])

Summary

In this tutorial, we covered the numpy.amin() statistical function of the Numpy library with its syntax, parameters, and returned values. along with a few code examples to help you understand how this function works.



About the author:
Aspiring Software developer working as a content writer. I like computer related subjects like Computer Networks, Operating system, CAO, Database, and I am also learning Python.