def to_data(value):
    """Standardize data types. Converts PyTorch tensors to Numpy arrays,
    and Numpy scalars to Python scalars."""
    if value.__class__.__module__.startswith('torch'):
        import torch
        if isinstance(value, torch.nn.parameter.Parameter):
            value = value.data
        if isinstance(value, torch.Tensor):
            if value.requires_grad:
                value = value.detach()
            value = value.cpu().numpy().copy()
        if not value.shape:
            value = value.item()
    if (value.__class__.__module__ == 'numpy' and value.__class__.__name__ !=
        'ndarray'):
        value = value.item()
    return value
