fn
normalize
→Tensornormalize(x: Tensor, p: float = 2.0, dim: int = 1, eps: float = 1e-12)Normalize a tensor to unit norm along a dimension.
Parameters
xTensorInput tensor.
pfloat= 2.0Exponent of the norm (default: 2.0 for Euclidean norm).
dimint= 1Dimension along which to normalize (default: 1).
epsfloat= 1e-12Small value added to the denominator for numerical stability.
Returns
TensorNormalized tensor with unit norm along dim.
Notes
along the chosen dimension. The eps clamp avoids division by
zero when the slice is all zeros. Use p=2 for cosine-similarity
style embeddings, p=1 for probability-simplex projection-like
behaviour, and p=inf for max-norm clipping.
Examples
>>> x = lucid.tensor([[3.0, 4.0]])
>>> F.normalize(x, p=2, dim=1)
tensor([[0.6, 0.8]])