mindspore.ops.aminmax
- mindspore.ops.aminmax(input, *, axis=0, keepdims=False)[source]
It returns the minimum and maximum value along the given axis of input tensor.
- Parameters
input (Tensor) – The input tensor, can be any dimension. Set the shape of input tensor as \((x_1, x_2, ..., x_N)\) .
- Keyword Arguments
axis (int, optional) – The dimension to reduce. The value range of axis is [-rank, rank), where "rank" is the dimension of input. If axis is None, computes the minimum and maximum value along the entire input tensor. Default:
0
.keepdims (bool, optional) – Whether to maintain dimension. When set to True, the output will keep the same dimension as the input, or the dimension specified by axis is reduced. Default:
False
.
- Returns
tuple (Tensor), containing the minimum value and maximum value of the input tensor.
If keepdims is True, the shape of output tensors is \((x_1, x_2, ..., x_{axis-1}, 1, x_{axis+1}, ..., x_N)\).
If keepdims is False, the shape of output tensors is \((x_1, x_2, ..., x_{axis-1}, x_{axis+1}, ..., x_N)\).
- Raises
TypeError – If keepdims is not a bool.
TypeError – If axis is not an int and not None.
ValueError – If axis is not in range [-rank, rank).
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor, ops >>> x = Tensor(np.array([0.0, 0.4, 0.6, 0.7, 0.1]), mindspore.float32) >>> output0, output1 = ops.aminmax(x) >>> print(output0, output1) 0.0 0.7 >>> output2, output3 = ops.aminmax(x, axis=-1, keepdims=True) >>> print(output2, output3) [0.] [0.7] >>> x = Tensor(np.array([[0.0, 0.4, 0.6, 0.7, 0.1], [0.78, 0.97, 0.5, 0.82, 0.99]]), mindspore.float32) >>> output4, output5 = ops.aminmax(x, axis=None, keepdims=True) >>> print(output4, output5) [[0.]] [[0.99]]