Recall & Review
beginner
What is a tensor in TensorFlow?
A tensor is a multi-dimensional array used to store data in TensorFlow. It can have any number of dimensions, like scalars (0D), vectors (1D), matrices (2D), or higher.
Click to reveal answer
beginner
How do you get the first element of a 1D tensor named
t?You use
t[0] to get the first element, just like accessing the first item in a list.Click to reveal answer
beginner
What does the slice
t[1:4] do on a 1D tensor?It extracts elements starting from index 1 up to, but not including, index 4. So it gets elements at positions 1, 2, and 3.
Click to reveal answer
intermediate
How do you select the second row and third column element from a 2D tensor
t?Use
t[1, 2]. The first index is the row (starting at 0), the second is the column.Click to reveal answer
intermediate
What does
t[:, 1] mean for a 2D tensor t?It selects all rows (the
:) but only the second column (index 1). This extracts a 1D tensor of that column.Click to reveal answer
What does
t[2:5] return for a 1D tensor t?✗ Incorrect
Slicing includes the start index (2) but excludes the end index (5), so it returns elements at 2, 3, and 4.
How do you select the last element of a 1D tensor
t?✗ Incorrect
Using
-1 as the index selects the last element in the tensor.What does
t[0, :] select in a 2D tensor t?✗ Incorrect
The first index 0 selects the first row; the colon
: selects all columns.If
t is a 3D tensor, what does t[:, 1, :] select?✗ Incorrect
The colon
: selects all in the first dimension, 1 selects the second index in the second dimension, and colon selects all in the third dimension.What is the shape of the tensor after slicing
t[:, 2:5] if t is shape (4, 6)?✗ Incorrect
Slicing columns from index 2 to 5 (3 columns) keeps all 4 rows, so shape is (4, 3).
Explain how to use indexing and slicing to extract a sub-tensor from a 2D tensor in TensorFlow.
Think about how you pick rows and columns like selecting cells in a spreadsheet.
You got /4 concepts.
Describe how negative indices work when indexing tensors in TensorFlow.
Imagine counting backwards from the last item.
You got /4 concepts.