latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.index_select
- tensorplay.functional.index_select(input, dim, index, *, out=None) Tensor[source]
Returns a new tensor which indexes the
inputtensor along dimensiondimusing the entries inindexwhich is a LongTensor.The returned tensor has the same number of dimensions as the original tensor (
input). Thedimth dimension has the same size as the length ofindex; other dimensions have the same size as in the original tensor.Note
The returned tensor does not use the same storage as the original tensor. If
outhas a different shape than expected, we silently change it to the correct shape, reallocating the underlying storage if necessary.- Parameters:
- Keyword Arguments:
out (Tensor, optional) – the output tensor.
Example:
>>> x = tensorplay.randn(3, 4) >>> x tensor([[ 0.1427, 0.0231, -0.5414, -1.0009], [-0.4664, 0.2647, -0.1228, -1.1068], [-1.1734, -0.6571, 0.7230, -0.6004]]) >>> indices = tensorplay.tensor([0, 2]) >>> tensorplay.index_select(x, 0, indices) tensor([[ 0.1427, 0.0231, -0.5414, -1.0009], [-1.1734, -0.6571, 0.7230, -0.6004]]) >>> tensorplay.index_select(x, 1, indices) tensor([[ 0.1427, -0.5414], [-0.4664, -0.1228], [-1.1734, 0.7230]])
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

