from typing import Any
import torch
import numbers


def python_scalar_to_tensor(data: Any, device: torch.device = torch.device("cpu")) -> Any:
    """ Converts a Python scalar number to a torch tensor and places it on the given device. """
    if isinstance(data, numbers.Number):
        data = torch.tensor([data], device=device)
    return data