Skip to content

tensor_conversion

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

Convert a dictionary to a rolling tensor.

PARAMETER DESCRIPTION
window

Rolling window.

TYPE: Deque

device

Device.

DEFAULT: 'cpu'

dtype

Dtype.

DEFAULT: float32

RETURNS DESCRIPTION
torch.Tensor

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

Convert a dataframe to a tensor.

PARAMETER DESCRIPTION
X

Dataframe.

TYPE: DataFrame

features

Set of possible features.

TYPE: OrderedSet

default_value

Value to use for features not present in x.

TYPE: float DEFAULT: 0

device

Device.

DEFAULT: 'cpu'

dtype

Dtype.

DEFAULT: float32

RETURNS DESCRIPTION
torch.Tensor

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

Convert a dictionary to a tensor.

PARAMETER DESCRIPTION
x

Dictionary.

TYPE: dict

features

Set of possible features.

TYPE: OrderedSet

default_value

Value to use for features not present in x.

TYPE: float DEFAULT: 0

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