Challenge - 5 Problems
Tensor Creator Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
What is the shape of the tensor created?
Consider the following PyTorch code that creates a tensor. What will be the shape of the resulting tensor?
PyTorch
import torch x = torch.ones((3, 4)) shape = x.shape print(shape)
Attempts:
2 left
💡 Hint
Remember that torch.ones takes a tuple for the shape.
✗ Incorrect
The torch.ones function creates a tensor filled with ones with the shape given by the tuple (3, 4). So the shape is (3, 4).
❓ Predict Output
intermediate1:30remaining
What is the output of this tensor creation?
What will be the output of the following PyTorch code?
PyTorch
import torch x = torch.tensor([[1, 2], [3, 4]], dtype=torch.float32) print(x)
Attempts:
2 left
💡 Hint
Check the dtype argument and how it affects the tensor values.
✗ Incorrect
The tensor is created with dtype=torch.float32, so all values are floats and printed with a decimal point.
❓ Model Choice
advanced1:30remaining
Which tensor creation method produces a tensor with random values between 0 and 1?
You want to create a tensor of shape (2, 3) filled with random values between 0 and 1. Which PyTorch function should you use?
Attempts:
2 left
💡 Hint
Think about which function generates random numbers.
✗ Incorrect
torch.rand creates a tensor with random values sampled uniformly from [0, 1).
❓ Metrics
advanced1:30remaining
How many elements are in the tensor created by torch.zeros((4, 5, 2))?
If you create a tensor with torch.zeros((4, 5, 2)), how many total elements does this tensor contain?
Attempts:
2 left
💡 Hint
Multiply the dimensions to find the total number of elements.
✗ Incorrect
The tensor shape is (4, 5, 2). Multiply 4 * 5 * 2 = 40 elements total.
🔧 Debug
expert2:00remaining
What error does this code raise?
What error will the following PyTorch code raise when executed?
PyTorch
import torch x = torch.tensor([1, 2, 3], dtype='float64') y = torch.ones(3, 3) z = x + y
Attempts:
2 left
💡 Hint
Check the shapes of x and y before adding.
✗ Incorrect
x has shape (3,) and y has shape (3, 3). They cannot be added because their shapes are incompatible for broadcasting.