TensorDataset
DatasetTensorDataset(tensors: Tensor = ())Dataset wrapping one or more Tensors, indexed along their first axis.
Each sample is the tuple (t1[i], t2[i], ...) where t1, t2, ...
are the wrapped tensors. All tensors must agree in their first
dimension (the sample axis); subsequent dimensions are independent.
Parameters
*tensorsTensor= ()tensors[0].shape[0].Raises
ValueErrorNotes
All wrapped tensors must share the same length along axis 0 — that
shared length defines __len__. The underlying tensors are
held by reference rather than copied, so any mutation visible on
the source tensors is also visible through the dataset. This keeps
construction O(1) but means the caller is responsible for not
invalidating the buffers (e.g. by resizing) during iteration.
Examples
>>> X = lucid.randn(100, 4)
>>> y = lucid.randint(0, 3, (100,))
>>> ds = TensorDataset(X, y)
>>> x_i, y_i = ds[0]Methods (3)
__init__
→None__init__(tensors: Tensor = ())Initialise the instance. See the class docstring for parameter semantics.
__getitem__
→tuple of Tensor__getitem__(index: int)Return (t[index] for t in self.tensors) as a tuple.
Parameters
indexintReturns
tuple of TensorOne element per wrapped tensor, in registration order.
__len__
→int__len__()Return the leading-dimension size shared by all wrapped tensors.