import torch
from typing import Dict


def standardize(
        x: torch.Tensor,
        stats: Dict[str, torch.Tensor]) -> torch.Tensor:
    """Standardize a tensor using precalculated global mean and std.

    Parameters
    ----------
    x
        A tensor to be standardized.
    stats
        A dict with keys ``mean`` and ``std``.

    Returns
    ----------
    Standardized x.
    """

    x_scaled = (x - stats['mean']) / stats['std']
    return x_scaled