📘
Access Dataset Sample
EasyPyTorch Datasets
Problem Statement
Given a PyTorch Dataset, extract a specific sample and return information about it.
Background
PyTorch Datasets support indexing — you can access individual samples, check the total number of samples, and iterate through the dataset.
Your Task
Write a function get_sample_info(dataset, index) that returns a dictionary with the total number of samples, the shape of the feature at the given index, and the label value at that index.
Output Format
Return a dictionary with keys: "num_samples" (int), "feature_shape" (list), "label_value" (int).
Example:
Input:
dataset with features [[1,2,3],[4,5,6]], labels [0,1], index=0
Output:
{"num_samples": 2, "feature_shape": [3], "label_value": 0}Reasoning:
We use len(dataset) for num_samples, dataset[0][0].shape for feature shape, and dataset[0][1].item() for label
Constraints:
- Index will be valid (within dataset bounds)
- Return feature_shape as a list, not torch.Size
- label_value should be a Python int, not tensor
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.