create
Create tensors from other array-like data, and change device and type.
- class AsTensor(dtype=None, device=None)[source]
Bases:
ArgRepr
Partial of the top-level PyTorch function
as_tensor
.- Parameters:
dtype (dtype, optional) – Torch dtype of the tensor to create. Defaults to
None
device (device, optional) – Torch device to create the tensor on. Defaults to
None
- class Create(dtype=None, device=None, requires_grad=False, pin_memory=False)[source]
Bases:
ArgRepr
Partial of the top-level PyTorch function
tensor
.- Parameters:
dtype (dtype, optional) – Torch dtype of the tensor to create. Defaults to
None
device (device, optional) – Torch device to create the tensor on. Defaults to
None
requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Defaults to
False
.pin_memory (bool, optional) – If set, returned tensor would be allocated in the pinned memory. Works only for CPU tensors. Defaults to
False
.
- class To(target, *args, **kwargs)[source]
Bases:
ArgRepr
Move or change a tensor or module to a different device or dtype.
Refer to the PyTorch documentation for more information.
- Parameters:
target (device or dtype) – The device or dtype to move the tensor or module to.
*args – Additional argument to pass to the to method.
**kwargs – Additional keyword arguments to pass to the to method.
- from_dataframe(df)[source]
Convert a pandas dataframe to a PyTorch tensor.
This is simply wrapper around the top-level PyTorch function
from_numpy
function called on the dataframe’svalues
attribute.- Parameters:
df (DataFrame) – The pandas dataframe to convert.
- Returns:
A PyTorch tensor sharing the memory with the dataframe’s data.
- Return type:
Tensor