tf.gather

Gather slices from params axis axis according to indices.

Used in the notebooks

Used in the tutorials

Gather slices from params axis axis according to indices. indices must be an integer tensor of any dimension (usually 0-D or 1-D).

For 0-D (scalar) indices:

$$\begin{align*} output[p_0, ..., p_{axis-1}, && &&& p_{axis + 1}, ..., p_{N-1}] = \\ params[p_0, ..., p_{axis-1}, && indices, &&& p_{axis + 1}, ..., p_{N-1}] \end{align*}$$

Where N = ndims(params).

For 1-D (vector) indices with batch_dims=0:

$$\begin{align*} output[p_0, ..., p_{axis-1}, && &i, &&p_{axis + 1}, ..., p_{N-1}] =\\ params[p_0, ..., p_{axis-1}, && indices[&i], &&p_{axis + 1}, ..., p_{N-1}] \end{align*}$$

In the general case, produces an output tensor where:

$$\begin{align*} output[p_0, &..., p_{axis-1}, & &i_{B}, ..., i_{M-1}, & p_{axis + 1}, &..., p_{N-1}] = \\ params[p_0, &..., p_{axis-1}, & indices[p_0, ..., p_{B-1}, &i_{B}, ..., i_{M-1}], & p_{axis + 1}, &..., p_{N-1}] \end{align*}$$

Where N = ndims(params), M = ndims(indices), and B = batch_dims. Note that params.shape[:batch_dims] must be identical to indices.shape[:batch_dims].

The shape of the output tensor is:

output.shape = params.shape[:axis] + indices.shape[batch_dims:] + params.shape[axis + 1:].

Note that on CPU, if an out of bound index is found, an error is returne