0
0
TensorFlowml~5 mins

Tensor shapes and reshaping in TensorFlow - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a tensor shape in TensorFlow?
A tensor shape is a list of integers that describes the size of the tensor in each dimension. For example, a shape of [3, 4] means the tensor has 3 rows and 4 columns.
Click to reveal answer
beginner
How do you reshape a tensor in TensorFlow?
You use the tf.reshape() function, which changes the shape of a tensor without changing its data. You provide the tensor and the new shape you want.
Click to reveal answer
intermediate
What does the '-1' argument mean in tf.reshape()?
The '-1' tells TensorFlow to automatically calculate the size of that dimension based on the other dimensions and the total number of elements.
Click to reveal answer
beginner
Why is it important to keep the total number of elements the same when reshaping?
Because reshaping only changes the shape, not the data. The total number of elements must stay the same to avoid errors and keep data consistent.
Click to reveal answer
beginner
What is the shape of a tensor created by tf.constant([[1, 2], [3, 4], [5, 6]])?
The shape is [3, 2] because there are 3 rows and 2 columns.
Click to reveal answer
What does tf.reshape(tensor, [-1, 2]) do?
AReshapes tensor to have 2 columns and automatically calculates rows
BReshapes tensor to have 2 rows and automatically calculates columns
CFlattens the tensor into a 1D array
DRaises an error because -1 is invalid
If a tensor has shape [4, 5], how many elements does it have?
A9
B20
C10
DNone of the above
Which function is used to check the shape of a tensor in TensorFlow?
Atf.size()
Btf.rank()
Ctf.reshape()
Dtf.shape()
What happens if you try to reshape a tensor to a shape with a different total number of elements?
ATensorFlow raises an error
BTensorFlow automatically adjusts the data
CTensorFlow fills missing values with zeros
DTensorFlow ignores extra elements
What is the shape of a scalar tensor in TensorFlow?
A[0]
B[1]
C[] (empty shape)
D[1,1]
Explain what tensor shape means and why it is important in TensorFlow.
Think about how shape tells you the size and layout of data.
You got /4 concepts.
    Describe how to reshape a tensor and what rules must be followed during reshaping.
    Consider how reshaping changes layout but not data.
    You got /4 concepts.