min#
- ivy.min(x, /, *, axis=None, keepdims=False, initial=None, where=None, out=None)[source]#
Calculate the minimum value of the input array
x
.Note
When the number of elements over which to compute the minimum value is zero, the minimum value is implementation-defined. Specification-compliant libraries may choose to raise an error, return a sentinel value (e.g., if
x
is a floating-point input array, returnNaN
), or return the maximum possible value for the input arrayx
data type (e.g., ifx
is a floating-point array, return+infinity
).Special Cases
For floating-point operands,
If
x_i
isNaN
, the minimum value isNaN
(i.e.,NaN
values propagate).
- Parameters:
x (
Union
[Array
,NativeArray
]) – Input array. Should have a real-valued data type.axis (
Optional
[Union
[int
,Sequence
[int
]]], default:None
) – axis or axes along which minimum values must be computed. By default, the minimum value must be computed over the entire array. If a tuple of integers, minimum values must be computed over multiple axes. Default:None
.keepdims (
bool
, default:False
) – optional boolean, ifTrue
, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see broadcasting). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.initial (
Optional
[Union
[int
,float
,complex
]], default:None
) – The maximum value of an output element. Must be present to allow computation on empty slice.where (
Optional
[Array
], default:None
) – Elements to compare for minimumout (
Optional
[Array
], default:None
) – optional output array, for writing the result to.
- Return type:
- Returns:
ret – if the minimum value was computed over the entire array, a zero-dimensional array containing the minimum value; otherwise, a non-zero-dimensional array containing the minimum values. The returned array must have the same data type as
x
.
This function conforms to the Array API Standard. This docstring is an extension of the docstring in the standard.
Both the description and the type hints above assumes an array input for simplicity, but this function is nestable, and therefore also accepts
ivy.Container
instances in place of any of the arguments.Examples
With
ivy.Array
input:>>> x = ivy.array([1, 2, 3]) >>> z = ivy.min(x) >>> print(z) ivy.array(1)
>>> x = ivy.array([0, 1, 2]) >>> z = ivy.array([0, 0, 0]) >>> y = ivy.min(x, out=z) >>> print(z) ivy.array(0)
>>> x = ivy.array([[0, 1, 2], [4, 6, 10]]) >>> y = ivy.min(x, axis=0, keepdims=True) >>> print(y) ivy.array([[0, 1, 2]])
>>> x = ivy.native_array([[0, 1, 2], [4, 6, 10]]) >>> y = ivy.min(x) >>> print(y) ivy.array(0)
With
ivy.Container
input:>>> x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([2, 3, 4])) >>> z = ivy.min(x) >>> print(z) { a: ivy.array(1), b: ivy.array(2) }
- Array.min(self, /, *, axis=None, keepdims=False, initial=None, where=None, out=None)[source]#
Calculate the minimum value of the input array
x
.- Parameters:
self (
Array
) – Input array. Should have a real-valued data type.axis (
Optional
[Union
[int
,Sequence
[int
]]], default:None
) – axis or axes along which minimum values must be computed. By default, the minimum value must be computed over the entire array. If a tuple of integers,minimum values must be computed over multiple axes. Default:None
.keepdims (
bool
, default:False
) – optional boolean, ifTrue
, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see broadcasting). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.initial (
Optional
[Union
[int
,float
,complex
]], default:None
) – The maximum value of an output element. Must be present to allow computation on empty slice.where (
Optional
[Array
], default:None
) – Elements to compare for minimumout (
Optional
[Array
], default:None
) – optional output array, for writing the result to.
- Return type:
Array
- Returns:
ret – if the minimum value was computed over the entire array, a zero-dimensional array containing the minimum value; otherwise, a non-zero-dimensional array containing the minimum values. The returned array must have the same data type as
x
.
Examples
With
ivy.Array
input:>>> x = ivy.array([3., 4., 5.]) >>> y = x.min() >>> print(y) ivy.array(3.)
>>> x = ivy.array([[-1, 0, 1], [2, 3, 4]]) >>> y = x.min(axis=1) >>> print(y) ivy.array([-1, 2])
>>> x = ivy.array([0.1, 1.1, 2.1]) >>> y = ivy.array(0.) >>> x.min(out=y) >>> print(y) ivy.array(0.1)
- Container.min(self, /, *, axis=None, keepdims=False, initial=None, where=None, key_chains=None, to_apply=True, prune_unapplied=False, map_sequences=False, out=None)[source]#
ivy.Container instance method variant of ivy.min. This method simply wraps the function, and so the docstring for ivy.min also applies to this method with minimal changes.
- Parameters:
self (
Container
) – Input container. Should have a real-valued data type.axis (
Optional
[Union
[int
,Sequence
[int
],Container
]], default:None
) – axis or axes along which minimum values must be computed. By default, the minimum value must be computed over the entire array. If a tuple of integers, minimum values must be computed over multiple axes. Default:None
.keepdims (
Union
[bool
,Container
], default:False
) – optional boolean, ifTrue
, the reduced axes (dimensions) must be included in the result as singleton dimensions, and, accordingly, the result must be compatible with the input array (see broadcasting). Otherwise, ifFalse
, the reduced axes (dimensions) must not be included in the result. Default:False
.initial (
Optional
[Union
[int
,float
,complex
,Container
]], default:None
) – The maximum value of an output element. Must be present to allow computation on empty slice.where (
Optional
[Union
[Array
,Container
]], default:None
) – Elements to compare for minimumout (
Optional
[Container
], default:None
) – optional output array, for writing the result to.
- Return type:
Container
- Returns:
ret – if the minimum value was computed over the entire array, a zero-dimensional array containing the minimum value; otherwise, a non-zero-dimensional array containing the minimum values. The returned array must have the same data type as
x
.
Examples
With
ivy.Container
input:>> > x = ivy.Container(a=ivy.array([1, 2, 3]), b=ivy.array([2, 3, 4])) >> > z = x.min() >> > print(z) {
a: ivy.array(1), b: ivy.array(2)
}
>>> x = ivy.Container(a=ivy.array([[1, 2, 3],[-1,0,2]]), ... b=ivy.array([[2, 3, 4], [0, 1, 2]])) >>> z = x.min(axis=1) >>> print(z) { a:ivy.array([1,-1]), b:ivy.array([2,0]) }