import torch


def normalize_tensor_0to1(t: torch.Tensor) -> torch.Tensor:
    """
    Normalizes a tensor such that the data in each sample in the batch will distribute between 0 and 1.
    """
    shape = t.size()
    t = t.view(t.size(0), -1)
    t -= t.min(1, keepdim=True)[0]
    t /= t.max(1, keepdim=True)[0]
    return t.view(shape)