0
0
PyTorchml~5 mins

Tensor creation (torch.tensor, zeros, ones, rand) in PyTorch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does torch.tensor() do in PyTorch?
It creates a tensor from a Python list or array with the exact values you provide.
Click to reveal answer
beginner
How do torch.zeros() and torch.ones() differ?
torch.zeros() creates a tensor filled with zeros, while torch.ones() creates a tensor filled with ones.
Click to reveal answer
beginner
What kind of values does torch.rand() generate?
It generates a tensor with random values between 0 and 1, following a uniform distribution.
Click to reveal answer
beginner
Why is tensor creation important in machine learning?
Tensors hold data like images or numbers that models learn from. Creating tensors correctly helps models train and predict well.
Click to reveal answer
beginner
How do you specify the shape of a tensor when using torch.zeros()?
You pass the shape as separate arguments or as a tuple, like torch.zeros(2, 3) or torch.zeros((2, 3)) to create a 2 by 3 tensor filled with zeros.
Click to reveal answer
Which function creates a tensor with all elements set to one?
Atorch.tensor()
Btorch.zeros()
Ctorch.rand()
Dtorch.ones()
What does torch.rand((3,2)) produce?
AA 3x2 tensor with random values between 0 and 1
BA 3x2 tensor filled with zeros
CA 3x2 tensor filled with ones
DA tensor created from a Python list
How do you create a tensor from a Python list [1, 2, 3]?
Atorch.rand([1, 2, 3])
Btorch.tensor([1, 2, 3])
Ctorch.ones([1, 2, 3])
Dtorch.zeros([1, 2, 3])
Which function would you use to create a tensor filled with zeros of shape (4, 5)?
Atorch.zeros((4, 5))
Btorch.ones((4, 5))
Ctorch.rand((4, 5))
Dtorch.tensor((4, 5))
What is the range of values generated by torch.rand()?
ABetween -1 and 1
BOnly zeros
CBetween 0 and 1
DOnly ones
Explain how to create a tensor filled with ones of shape (3, 4) using PyTorch.
Think about the function that fills with ones and how to specify size.
You got /4 concepts.
    Describe the difference between torch.tensor() and torch.rand().
    One uses your data, the other creates random numbers.
    You got /4 concepts.