torch.nn.functional.normalize(input, p=2.0, dim=1, eps=1e-12, out=None)[source]

Performs LpL_p normalization of inputs over specified dimension.

For a tensor input of sizes (n0,...,ndim,...,nk)(n_0, ..., n_{dim}, ..., n_k), each ndimn_{dim} -element vector vv along dimension dim is transformed as

v=vmax(vp,ϵ).v = \frac{v}{\max(\lVert v \rVert_p, \epsilon)}.

With the default arguments it uses the Euclidean norm over vectors along dimension 11 for normalization.

  • input – input tensor of any shape

  • p (float) – the exponent value in the norm formulation. Default: 2

  • dim (int) – the dimension to reduce. Default: 1

  • eps (float) – small value to avoid division by zero. Default: 1e-12

  • out (Tensor, optional) – the output tensor. If out is used, this operation won’t be differentiable.


Access comprehensive developer documentation for PyTorch

View Docs


Get in-depth tutorials for beginners and advanced developers

View Tutorials


Find development resources and get your questions answered

View Resources