Module-level Graded Quiz: Tensor and Dataset :Introduction to Neural Networks and PyTorch (IBM AI Engineering Professional Certificate) Answers 2025
1. Question 1
Result of:
a = torch.tensor([1,2,3])
a.dtype
-
✅ torch.int64
-
❌ torch.float32
-
❌ LongTensor
-
❌ Float
Explanation:
PyTorch defaults integer tensors to int64 unless specified otherwise.
2. Question 2
Tensor type for unsigned integers used in 8-bit images:
-
✅ Byte
-
❌ Integer
-
❌ Float
-
❌ Double
Explanation:
8-bit images → values 0–255 → PyTorch uses torch.uint8 (Byte).
3. Question 3
What is a 2D tensor?
-
✅ A matrix: rows = samples, columns = features
-
❌ Scalar
-
❌ 1D array
-
❌ Single color channel
Explanation:
A 2D tensor is just a matrix.
4. Question 4
Method to get number of dimensions (rank):
-
❌ shape()
-
❌ numel()
-
❌ size()
-
✅ ndimension()
Explanation:tensor.ndimension() returns the rank.
5. Question 5
Indexing second row, third column:
-
✅ tensor[1, 2]
-
❌ tensor[1][2]
-
❌ tensor[2][1]
-
❌ tensor[2, 1]
Explanation:
Indexing is zero-based → row 1, column 2.
6. Question 6
Given:
a = torch.tensor([[0,1,1],[1,0,1]])
a.size() and a.ndimension():
-
✅ (2, 3), 2
-
❌ (3,2), 3
-
❌ (2,3), 3
-
❌ (3,2), 2
Explanation:
2 rows × 3 columns → rank 2.
7. Question 7
Method to override to access items in dataset:
-
❌ iter
-
❌ init
-
✅ getitem
-
❌ len
Explanation:__getitem__ retrieves items by index.
8. Question 8
How to apply a transform to a dataset:
-
✅ Pass transform to the dataset constructor
-
❌ Call transform() on dataset
-
❌ apply_transform()
-
❌ Manually transform each sample
Explanation:
Transforms are injected into the dataset class.
9. Question 9
Technique for applying multiple transforms:
-
✅ Compose
-
❌ Single transform
-
❌ Splitting data
-
❌ Convert to tensors
Explanation:transforms.Compose([...]) chains operations.
10. Question 10
Purpose of Image.open():
-
❌ Get image path
-
✅ Read and load image into a PIL image format
-
❌ Display image
-
❌ Load directly into tensor
Explanation:Image.open() loads an image into a PIL object.
🧾 Summary Table
| Q# | Correct Answer |
|---|---|
| 1 | torch.int64 |
| 2 | Byte |
| 3 | Matrix (rows=samples, columns=features) |
| 4 | ndimension() |
| 5 | tensor[1, 2] |
| 6 | (2, 3), 2 |
| 7 | getitem |
| 8 | Pass transform in constructor |
| 9 | Compose |
| 10 | Load image via Image.open() |