mindspore.Tensor.min
- Tensor.min() Tensor
Returns the minimum value of the self tensor.
- Returns
Scalar Tensor with the same dtype as self, the minimum value of the self.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor >>> x = Tensor(np.array([0.0, 0.4, 0.6, 0.7, 0.1]), mindspore.float32) >>> output = Tensor.min(x) >>> print(output) 0.0
- Tensor.min(dim, keepdim=False)
Calculates the minimum value along with the given dim for the self tensor, and returns the minimum values and indices.
- Parameters
- Returns
tuple (Tensor), tuple of 2 tensors, containing the minimum value of the self tensor along the given dimension dim and the corresponding index.
values (Tensor) - The minimum value of self tensor along the given dimension dim, with the same shape as index, and same dtype as self.
index (Tensor) - The index for the minimum value of the self tensor, with dtype int64. If keepdim is
True
, the shape of output tensors is \((self_1, self_2, ..., self_{dim-1}, 1, self_{dim+1}, ..., self_N)\). Otherwise, the shape is \((self_1, self_2, ..., self_{dim-1}, self_{dim+1}, ..., self_N)\) .
- Raises
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore >>> import numpy as np >>> from mindspore import Tensor >>> x = Tensor(np.array([0.0, 0.4, 0.6, 0.7, 0.1]), mindspore.float32) >>> output, index = x.min(0, keepdim=True) >>> print(output, index) [0.0] [0]
- Tensor.min(axis=None, keepdims=False, *, initial=None, where=True, return_indices=False) Tensor | number.Number
Return the minimum of a tensor or minimum along an axis.
Note
When axis is
None
, keepdims and subsequent parameters have no effect. At the same time, the index is fixed to return 0.- Parameters
axis (Union[None, int, list, tuple of ints], optional) – An axis or axes along which to operate. By default, flattened input is used. If axis is a tuple of ints, the minimum is selected over multiple axes, instead of a single axis or all the axes as before. Default:
None
.keepdims (bool, optional) – If
True
, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. Default:False
.
- Keyword Arguments
initial (scalar, optional) – The minimum value of an output element. Must be present to allow computation on empty slice. Default:
None
.where (Tensor[bool], optional) – A boolean tensor which is broadcasted to match the dimensions of array, and selects elements to include in the reduction. If non-default value is passed, initial must also be provided. Default:
True
.return_indices (bool, optional) – Whether to return the index of the minimum value. Default:
False
. If axis is a list or tuple of ints, it must beFalse
.
- Returns
Tensor or scalar, minimum of self tensor. If axis is
None
, the result is a scalar value. If axis is given, the result is a tensor of dimensionself.ndim - 1
.- Raises
TypeError – If arguments have types not specified above.
See also
mindspore.Tensor.argmin()
: Return the indices of the minimum values along an axis.mindspore.Tensor.argmax()
: Return the indices of the maximum values along an axis.mindspore.Tensor.max()
: Return the minimum of a tensor or minimum along an axis.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import numpy as np >>> from mindspore import Tensor >>> a = Tensor(np.arange(4).reshape((2, 2)).astype('float32')) >>> output = Tensor.min(a) >>> print(output) 0.0 >>> output = Tensor.min(a, axis=0) >>> print(output) [0. 1.] >>> output = Tensor.min(a, axis=0, initial=9, where=Tensor([False])) >>> print(output) [9. 9.] >>> output = Tensor.min(a, axis=0, initial=9, where=Tensor([False, True])) >>> print(output) [9. 1.] >>> value, indices = Tensor.min(a, axis=0, return_indices=True) >>> print(value) [0. 1.] >>> print(indices) [0 0]