📘
Create TensorDataset
EasyPyTorch Datasets
Problem Statement
Create a TensorDataset from feature and label tensors.
Background
TensorDataset wraps tensors so they can be used with PyTorch's data loading utilities, pairing features with their corresponding labels automatically.
Your Task
Write a function create_dataset(features, labels) that creates a TensorDataset and returns the number of samples it contains.
Output Format
Return a single integer.
Example:
Input:
features=torch.tensor([[1.0, 2.0], [3.0, 4.0]]), labels=torch.tensor([0, 1])
Output:
TensorDataset with 2 samples
Reasoning:
We use TensorDataset to wrap the feature and label tensors together
Constraints:
- Use torch.utils.data.TensorDataset
- Both tensors will have the same first dimension
- Features is a 2D tensor, labels is a 1D tensor
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.