Skip to content

tensor_conversion

deque2rolling_tensor(window, device='cpu', dtype=torch.float32)

Convert a dictionary to a rolling tensor.

PARAMETER DESCRIPTION
x

Dictionary.

window

Rolling window.

TYPE: Deque

device

Device.

DEFAULT: 'cpu'

dtype

Dtype.

DEFAULT: float32

RETURNS DESCRIPTION
torch.Tensor

df2tensor(X, device='cpu', dtype=torch.float32)

Convert a dataframe to a tensor.

PARAMETER DESCRIPTION
X

Dataframe.

TYPE: DataFrame

device

Device.

DEFAULT: 'cpu'

dtype

Dtype.

DEFAULT: float32

RETURNS DESCRIPTION
torch.Tensor

dict2tensor(x, device='cpu', dtype=torch.float32)

Convert a dictionary to a tensor.

PARAMETER DESCRIPTION
x

Dictionary.

TYPE: dict

device

Device.

TYPE: str DEFAULT: 'cpu'

dtype

Dtype.

TYPE: dtype DEFAULT: float32

RETURNS DESCRIPTION
torch.Tensor

float2tensor(y, device='cpu', dtype=torch.float32)

Convert a float to a tensor.

PARAMETER DESCRIPTION
y

Float.

TYPE: Union[float, int, RegTarget, dict]

device

Device.

DEFAULT: 'cpu'

dtype

Dtype.

DEFAULT: float32

RETURNS DESCRIPTION
torch.Tensor

labels2onehot(y, classes, n_classes=None, device='cpu', dtype=torch.float32)

Convert a label or a list of labels to a one-hot encoded tensor.

PARAMETER DESCRIPTION
y

Label or list of labels.

TYPE: Union[ClfTarget, Series]

classes

Classes.

TYPE: OrderedSet[ClfTarget]

n_classes

Number of classes.

TYPE: Optional[int] DEFAULT: None

device

Device.

DEFAULT: 'cpu'

dtype

Dtype.

DEFAULT: float32

RETURNS DESCRIPTION
torch.Tensor