megengine.functional.normalize¶
- normalize(inp, ord=None, axis=None, eps=1e-12)[source]¶
Performs \(L_p\) normalization of input tensor along given axis.
For a tensor of shape \((n_0, ..., n_{dim}, ..., n_k)\), each \(n_{dim}\) -element vector \(v\) along dimension
axis
is transformed as:\[v = \frac{v}{\max(\lVert v \rVert_p, \epsilon)}.\]- Parameters
- Return type
- Returns
normalized output tensor.
See also
Examples
>>> x = Tensor([[1, 2, 3], [4, 5, 6]]) >>> F.normalize(x, ord=2, axis=0) Tensor([[0.2425 0.3714 0.4472] [0.9701 0.9285 0.8944]], device=xpux:0) >>> F.normalize(x, ord=2, axis=1) Tensor([[0.2673 0.5345 0.8018] [0.4558 0.5698 0.6838]], device=xpux:0)