Selecting Elements from a Tensor

In this lesson, we look at selecting elements from a tensor.

Selecting tensor with index

If you are already familiar with the NumPy array, you can use the same methods to select tensors by [] operations.

Take a 2-dimensional tensor as an example. Let’s consider it as a matrix.

  • tensor[2, 3]: Get only one value.
  • tensor[:, 1]: Get the second column from the tensor.
  • tensor[1, :]: Get the second row from the tensor.

For higher-dimensional tensors, the operations are the same. Such as tensor[:, 2, :].

Get hands-on with 1200+ tech skills courses.