import torch


def l2_norm_standardize(features) -> torch.Tensor:
    """
    This function standarizes the features by their L2-Norm.
    """

    # L2-Norm Sum of Squares of the output all_features
    fnorm = torch.norm(features, p=2, dim=1, keepdim=True)
    # Divide by L2-Norm (equivalent std.) -> Standardization
    standardized_features = features.div(fnorm.expand_as(features))
    standardized_features = standardized_features.view(
        standardized_features.size(0), -1)

    return standardized_features