0
0
PyTorchml~5 mins

Tensor shapes and dimensions in PyTorch - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a tensor in PyTorch?
A tensor is a multi-dimensional array used to store data. It can have any number of dimensions, like a list (1D), matrix (2D), or higher.
Click to reveal answer
beginner
What does the shape of a tensor represent?
The shape shows the size of the tensor in each dimension. For example, shape (3, 4) means 3 rows and 4 columns in a 2D tensor.
Click to reveal answer
beginner
How do you get the number of dimensions of a tensor in PyTorch?
Use the `.dim()` method. It returns how many dimensions the tensor has.
Click to reveal answer
beginner
What is the difference between a 1D and 2D tensor?
A 1D tensor is like a list of numbers (shape like [5]). A 2D tensor is like a table or matrix with rows and columns (shape like [3, 4]).
Click to reveal answer
intermediate
How can you change the shape of a tensor without changing its data?
You can use the `.view()` or `.reshape()` methods to change the shape while keeping the same data.
Click to reveal answer
What does the shape (2, 3, 4) of a tensor mean?
A2 rows, 3 columns, and 4 layers
B2 matrices, each with 3 rows and 4 columns
CA 2D tensor with 3 rows and 4 columns
DA 1D tensor with 24 elements
Which PyTorch method returns the number of dimensions of a tensor?
A.dim()
B.shape
C.size()
D.length()
If a tensor has shape (5,), what kind of tensor is it?
A1D tensor
B3D tensor
C2D tensor
DScalar
Which method can you use to change the shape of a tensor without changing its data?
A.change_shape()
B.convert()
C.reshape()
D.resize()
What will `tensor.shape` return for a tensor with 3 rows and 4 columns?
A(4, 3)
B7
C12
D(3, 4)
Explain what tensor shape and dimensions mean in PyTorch and why they matter.
Think about how data is organized in rows, columns, and layers.
You got /3 concepts.
    Describe how to check and change the shape of a tensor in PyTorch with code examples.
    Show how to get shape and dimension, then reshape a tensor.
    You got /4 concepts.