# tensorflow::ops::GatherV2 Class Reference

# tensorflow::ops::GatherV2

`#include <array_ops.h>`

[Gather](https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather#classtensorflow_1_1ops_1_1_gather) slices from `params` axis `axis` according to `indices`.

## Summary

`indices` must be an integer tensor of any dimension (usually 0-D or 1-D). Produces an output tensor with shape `params.shape[:axis] + indices.shape[batch_dims:] + params.shape[axis + 1:]` where:


```
    # Scalar indices (output is rank(params) - 1).
    output[a_0, ..., a_n, b_0, ..., b_n] =
      params[a_0, ..., a_n, indices, b_0, ..., b_n]
```

<br />


```
    # Vector indices (output is rank(params)).
    output[a_0, ..., a_n, i, b_0, ..., b_n] =
      params[a_0, ..., a_n, indices[i], b_0, ..., b_n]
```

<br />


```
    # Higher rank indices (output is rank(params) + rank(indices) - 1).
    output[a_0, ..., a_n, i, ..., j, b_0, ... b_n] =
      params[a_0, ..., a_n, indices[i, ..., j], b_0, ..., b_n]
```

<br />


![](https://www.tensorflow.org/static/versions/r2.3/api_docs/cc/images/Gather.png)

<br />

Note that on CPU, if an out of bound index is found, an error is returned. On GPU, if an out of bound index is found, a 0 is stored in the corresponding output value.

See also `tf.batch_gather` and `tf.gather_nd`.

Arguments:

- scope: A [Scope](https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- params: The tensor from which to gather values. Must be at least rank `axis + 1`.
- indices: Index tensor. Must be in range `[0, params.shape[axis])`.
- axis: The axis in `params` to gather `indices` from. Defaults to the first dimension. Supports negative indexes.

<br />

Returns:

- `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output`: Values from `params` gathered from indices given by `indices`, with shape `params.shape[:axis] + indices.shape + params.shape[axis + 1:]`.

<br />

| ### Constructors and Destructors ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2_1afff9f85abc36b6134f07ac9264e6b6b7(const ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input params, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input indices, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input axis)` ||
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2_1a8f8e2e0c5f4693b13f8a2c747ff77d8b(const ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input params, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input indices, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input axis, const https://www.tensorflow.org/versions/r2.3/api_docs/cc/struct/tensorflow/ops/gather-v2/attrs#structtensorflow_1_1ops_1_1_gather_v2_1_1_attrs & attrs)` ||

| ### Public attributes ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2_1acada34664fa1ed40763d7823796966d3` | `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2_1a8d4dd95b0f18afade1621c680ecdac1a` | `::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` |

| ### Public functions ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2_1abc465824a7b865f5bdfa41eb624a1bb7() const ` | `::tensorflow::Node *` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2_1a967966fdcae665e9578c3e9512e18b4c() const ` | ` `` ` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2_1a5f58668891b9a0ae4a460fe84c7b4d5c() const ` | ` `` ` |

| ### Public static functions ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2_1a96a2555cae1e27560651b09777fece7c(int64 x)` | `https://www.tensorflow.org/versions/r2.3/api_docs/cc/struct/tensorflow/ops/gather-v2/attrs#structtensorflow_1_1ops_1_1_gather_v2_1_1_attrs` |

| ### Structs ||
|---|---|
| [tensorflow::ops::GatherV2::Attrs](https://www.tensorflow.org/versions/r2.3/api_docs/cc/struct/tensorflow/ops/gather-v2/attrs) | Optional attribute setters for [GatherV2](https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/gather-v2#classtensorflow_1_1ops_1_1_gather_v2). |

## Public attributes

### operation

```
Operation operation
```

### output

```
::tensorflow::Output output
```

## Public functions

### GatherV2

```
 GatherV2(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input params,
  ::tensorflow::Input indices,
  ::tensorflow::Input axis
)
```

### GatherV2

```
 GatherV2(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input params,
  ::tensorflow::Input indices,
  ::tensorflow::Input axis,
  const GatherV2::Attrs & attrs
)
```

### node

```
::tensorflow::Node * node() const 
```

### operator::tensorflow::Input

```
 operator::tensorflow::Input() const 
```

### operator::tensorflow::Output

```
 operator::tensorflow::Output() const 
```

## Public static functions

### BatchDims

```
Attrs BatchDims(
  int64 x
)
```