latest (dev)
Copy
Latest development documentation · Updated 2026-10-15
tensorplay.functional.gather
- tensorplay.functional.gather(input, dim, index, *, sparse_grad=False, out=None) Tensor[source]
Gathers values along an axis specified by dim.
For a 3-D tensor the output is specified by:
out[i][j][k] = input[index[i][j][k]][j][k] # if dim == 0 out[i][j][k] = input[i][index[i][j][k]][k] # if dim == 1 out[i][j][k] = input[i][j][index[i][j][k]] # if dim == 2inputandindexmust have the same number of dimensions. It is also required thatindex.size(d) <= input.size(d)for all dimensionsd != dim.outwill have the same shape asindex. Note thatinputandindexdo not broadcast against each other. Whenindexis empty, we always return an empty output with the same shape without further error checking.- Parameters:
- Keyword Arguments:
Example:
>>> t = tensorplay.tensor([[1, 2], [3, 4]]) >>> tensorplay.gather(t, 1, tensorplay.tensor([[0, 0], [1, 0]])) tensor([[ 1, 1], [ 4, 3]])
Help improve this page
Found an error, an unclear step, or a missing example?
Was this page helpful?

