NumPy Tutorial NumPy Statistics NumPy Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

NumPy - amin() function



The NumPy amin() function returns the minimum of an array or minimum along the specified axis.

Syntax

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

Parameters

a Required. Specify the input array.
axis Optional. Specify axis or axes along which to operate. The default, axis=None, operation is performed on flattened array.
out Optional. Specify the output array in which to place the result. It must have the same shape as the expected output.
keepdims Optional. If this is set to True, the reduced axes are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array.

Return Value

Returns minimum of a. If axis is None, the result is a scalar value. If axis is given, the result is an array of dimension a.ndim - 1.

Example: amin() of flattened array

In the example below, amin() function is used to return the minimum of all values present in the array.

import numpy as np
Arr = np.array([[10,20],[30, 40]])

print("Array is:")
print(Arr)

#minimum of all values
print("\nMinimum of all values:", np.amin(Arr))

The output of the above code will be:

Array is:
[[10 20]
 [30 40]]

Minimum of all values: 10

Example: amin() with axis parameter

When axis parameter is provided, minimum is calculated over the specified axes as shown in the example below.

import numpy as np
Arr = np.array([[10,20,30],[70,80,90]])

print("Array is:")
print(Arr)

#minimum along axis=0
print("\nMinimum along axis=0")
print(np.amin(Arr, axis=0))

#minimum along axis=1
print("\nMinimum along axis=1")
print(np.amin(Arr, axis=1))

The output of the above code will be:

Array is:
[[10 20 30]
 [70 80 90]]

Minimum along axis=0
[10 20 30]

Minimum along axis=1
[10 70]

❮ NumPy - Functions

5