mindspore.numpy.ptp
- mindspore.numpy.ptp(x, axis=None, keepdims=False)[源代码]
Range of values (maximum - minimum) along an axis. The name of the function comes from the acronym for “peak to peak”.
Note
Numpy arguments dtype and out are not supported.
- Parameters
x (Tensor) – Input tensor.
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 array. 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 input tensor. If the default value is passed, then keepdims will not be passed through to the ptp method of sub-classes of tensor, however any non-default value will be. Default is False.
- Returns
Tensor.
- Raises
TypeError – If inputs have types not specified above.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.numpy as np >>> x = np.array([[4.0, 9.0, 2.0, 10.0], [6.0, 9.0, 7.0, 12.0]]) >>> print(np.ptp(x, axis=1)) [8. 6.] >>> print(np.ptp(x, axis=0)) [2. 0. 5. 2.]