mindspore.Tensor.ptp

View Source On Gitee
Tensor.ptp(axis=None, keepdims=False)[source]

The name of the function comes from the acronym for "peak to peak". Calculate the difference between the maximum value and the minimum value along the axis.

Note

Numpy argument out is not supported.

Parameters
  • axis (Union[None, int, tuple(int)]) – Axis or axes along which the range is computed. The default is to compute the variance of the flattened tensor. Default: None .

  • keepdims (bool) – If this is set to 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 tensor. Default is False .

Returns

Tensor.

Raises

TypeError – If self is not a tensor, or axis and keepdims have types not specified above.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore import Tensor
>>> x = Tensor([[4.0, 9.0, 2.0, 10.0], [6.0, 9.0, 7.0, 12.0]]).astype("float32")
>>> print(x.ptp(axis=1))
[8. 6.]
>>> print(x.ptp(axis=0))
[2. 0. 5. 2.]