mindspore.ops.Renorm

class mindspore.ops.Renorm(p, dim, maxnorm)[source]

Renormalizes the sub-tensors along dimension dim, and each sub-tensor’s p-norm should not exceed the ‘maxnorm’. The values of current sub-tensor don’t need change if the p-norm of the sub-tensor is less than maxnorm. Otherwise the sub-tensor needs to be modified to the original value of the corresponding position divided by the p-norm of the substensor and then multiplied by maxnorm.

Refer to mindspore.ops.renorm() for more details.

Parameters
  • p (int) – Power of norm calculation.

  • dim (int) – The dimension that expected to get the slice-tensor.

  • maxnorm (float32) – Max norm.

Inputs:
  • x (Tensor) - A Tensor, types: float32 or float16.

Outputs:

Tensor, has the same dtype and shape as input.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([[1, 1, 1], [2, 2, 2], [3, 3, 3]]), mindspore.float32)
>>> y = ops.Renorm(p=1, dim=0, maxnorm=5.)(x)
>>> print(y)
[[1.       1.        1.        ]
[1.6666666 1.6666666 1.6666666 ]
[1.6666667 1.6666667 1.6666667 ]]