NumPy min()

The numpy.min() function returns the minimum value in an array or the minimum value along a specified axis.

Syntax

</>
Copy
numpy.min(a, axis=None, out=None, keepdims=False, initial=None, where=True)

Parameters

ParameterTypeDescription
aarray_likeInput array from which the minimum value is computed.
axisNone, int, or tuple of ints, optionalAxis or axes along which to find the minimum. If None, the minimum of the flattened array is returned.
outndarray, optionalAlternative output array to store the result. Must have the same shape as expected output.
keepdimsbool, optionalIf True, the reduced dimensions are kept as size one, allowing proper broadcasting.
initialscalar, optionalSpecifies an initial minimum value for empty arrays.
wherearray_like of bool, optionalSpecifies elements to include in the comparison for the minimum value.

Return Value

Returns a scalar or an array containing the minimum values. If axis=None, a scalar value is returned. If axis is specified, an array with the reduced dimension is returned.


Examples

1. Finding the Minimum Value in an Array

This example demonstrates finding the smallest element in an array.

</>
Copy
import numpy as np

# Define an array
arr = np.array([3, 1, 4, 1, 5, 9, 2, 6])

# Find the minimum value
min_value = np.min(arr)

# Print the result
print("Minimum value in the array:", min_value)

Output:

Minimum value in the array: 1