Loading...
Given a PyTorch Dataset, extract a specific sample and return information about it.
PyTorch Datasets support indexing — you can access individual samples, check the total number of samples, and iterate through the dataset.
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.
Return a dictionary with keys: "num_samples" (int), "feature_shape" (list), "label_value" (int).
dataset with features [[1,2,3],[4,5,6]], labels [0,1], index=0
{"num_samples": 2, "feature_shape": [3], "label_value": 0}We use len(dataset) for num_samples, dataset[0][0].shape for feature shape, and dataset[0][1].item() for label