import torch


def _dict_to_tensor(numpy_array_dict, device):
    """Convert numpy array to a tensor
    :param numpy_array_dict dict: a dictionary of np.array
    :param device: put tensor on cpu or gpu
    :return: a dictionary of torch tensors
    """
    if isinstance(numpy_array_dict, dict):
        torch_dict = {}
        for k, v in numpy_array_dict.items():
            torch_dict[k] = torch.from_numpy(numpy_array_dict[k]).to(device)
        return torch_dict
    else:
        return torch.from_numpy(numpy_array_dict).to(device)