Stay organized with collections
Save and categorize content based on your preferences.
tensorflow::
ops::
GatherNd
#include <array_ops.h>
Gather
slices from
params
into a
Tensor
with shape specified by
indices
.
Summary
indices
is a K-dimensional integer tensor, best thought of as a (K-1)-dimensional tensor of indices into
params
, where each element defines a slice of
params
:
output[\\(i_0, ..., i_{K-2}\\)] = params[indices[\\(i_0, ..., i_{K-2}\\)]]
Whereas in
tf.gather
indices
defines slices into the
axis
dimension of
params
, in
tf.gather_nd
,
indices
defines slices into the first
N
dimensions of
params
, where
N = indices.shape[-1]
.
The last dimension of
indices
can be at most the rank of
params
:
indices.shape[-1] <= params.rank
The last dimension of
indices
corresponds to elements (if
indices.shape[-1] == params.rank
) or slices (if
indices.shape[-1] < params.rank
) along dimension
indices.shape[-1]
of
params
. The output tensor has shape
indices.shape[:-1] + params.shape[indices.shape[-1]:]
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.
Some examples below.
Simple indexing into a matrix:
indices = [[0, 0], [1, 1]]
params = [['a', 'b'], ['c', 'd']]
output = ['a', 'd']
Slice indexing into a matrix:
indices = [[1], [0]]
params = [['a', 'b'], ['c', 'd']]
output = [['c', 'd'], ['a', 'b']]
Indexing into a 3-tensor:
indices = [[1]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[['a1', 'b1'], ['c1', 'd1']]]
indices = [[0, 1], [1, 0]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [['c0', 'd0'], ['a1', 'b1']]
indices = [[0, 0, 1], [1, 0, 1]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = ['b0', 'b1']
Batched indexing into a matrix:
indices = [[[0, 0]], [[0, 1]]]
params = [['a', 'b'], ['c', 'd']]
output = [['a'], ['b']]
Batched slice indexing into a matrix:
indices = [[[1]], [[0]]]
params = [['a', 'b'], ['c', 'd']]
output = [[['c', 'd']], [['a', 'b']]]
Batched indexing into a 3-tensor:
indices = [[[1]], [[0]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[[['a1', 'b1'], ['c1', 'd1']]],
[[['a0', 'b0'], ['c0', 'd0']]]]
indices = [[[0, 1], [1, 0]], [[0, 0], [1, 1]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [[['c0', 'd0'], ['a1', 'b1']],
[['a0', 'b0'], ['c1', 'd1']]]
indices = [[[0, 0, 1], [1, 0, 1]], [[0, 1, 1], [1, 1, 0]]]
params = [[['a0', 'b0'], ['c0', 'd0']],
[['a1', 'b1'], ['c1', 'd1']]]
output = [['b0', 'b1'], ['d0', 'c1']]
See also
tf.gather
and
tf.batch_gather
.
Args:
-
scope: A
Scope
object
-
params: The tensor from which to gather values.
-
indices: Index tensor.
Returns:
-
Output
: Values from
params
gathered from indices given by
indices
, with shape
indices.shape[:-1] + params.shape[indices.shape[-1]:]
.
Public attributes
Public functions
node
::tensorflow::Node * node() const
operator::tensorflow::Input() const
operator::tensorflow::Output
operator::tensorflow::Output() const
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2021-08-16 UTC.
[null,null,["Last updated 2021-08-16 UTC."],[],[],null,["# tensorflow::ops::GatherNd Class Reference\n\ntensorflow::\nops::\nGatherNd\n===========================\n\n`\n#include \u003carray_ops.h\u003e\n`\n\n\n[Gather](/versions/r2.6/api_docs/cc/class/tensorflow/ops/gather#classtensorflow_1_1ops_1_1_gather)\nslices from\n`\nparams\n`\ninto a\n[Tensor](/versions/r2.6/api_docs/cc/class/tensorflow/tensor#classtensorflow_1_1_tensor)\nwith shape specified by\n`\nindices\n`\n.\n\nSummary\n-------\n\n\n`\nindices\n`\nis a K-dimensional integer tensor, best thought of as a (K-1)-dimensional tensor of indices into\n`\nparams\n`\n, where each element defines a slice of\n`\nparams\n`\n: \n\n```scdoc\noutput[\\\\(i_0, ..., i_{K-2}\\\\)] = params[indices[\\\\(i_0, ..., i_{K-2}\\\\)]]\n```\n\n\u003cbr /\u003e\n\n\nWhereas in\n`\ntf.gather\n`\n`\nindices\n`\ndefines slices into the\n`\naxis\n`\ndimension of\n`\nparams\n`\n, in\n`\ntf.gather_nd\n`\n,\n`\nindices\n`\ndefines slices into the first\n`\nN\n`\ndimensions of\n`\nparams\n`\n, where\n`\nN = indices.shape[-1]\n`\n.\n\n\nThe last dimension of\n`\nindices\n`\ncan be at most the rank of\n`\nparams\n`\n: \n\n```text\nindices.shape[-1] \u003c= params.rank\n```\n\n\u003cbr /\u003e\n\n\nThe last dimension of\n`\nindices\n`\ncorresponds to elements (if\n`\nindices.shape[-1] == params.rank\n`\n) or slices (if\n`\nindices.shape[-1] \u003c params.rank\n`\n) along dimension\n`\nindices.shape[-1]\n`\nof\n`\nparams\n`\n. The output tensor has shape \n\n```cplint\nindices.shape[:-1] + params.shape[indices.shape[-1]:]\n```\n\n\u003cbr /\u003e\n\n\nNote 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.\n\n\nSome examples below.\n\n\nSimple indexing into a matrix:\n\n\n```text\n indices = [[0, 0], [1, 1]]\n params = [['a', 'b'], ['c', 'd']]\n output = ['a', 'd']\n```\n\n\u003cbr /\u003e\n\n\nSlice indexing into a matrix:\n\n\n```text\n indices = [[1], [0]]\n params = [['a', 'b'], ['c', 'd']]\n output = [['c', 'd'], ['a', 'b']]\n```\n\n\u003cbr /\u003e\n\n\nIndexing into a 3-tensor:\n\n\n```text\n indices = [[1]]\n params = [[['a0', 'b0'], ['c0', 'd0']],\n [['a1', 'b1'], ['c1', 'd1']]]\n output = [[['a1', 'b1'], ['c1', 'd1']]]\n```\n\n\u003cbr /\u003e\n\n\n```text\n indices = [[0, 1], [1, 0]]\n params = [[['a0', 'b0'], ['c0', 'd0']],\n [['a1', 'b1'], ['c1', 'd1']]]\n output = [['c0', 'd0'], ['a1', 'b1']]\n```\n\n\u003cbr /\u003e\n\n\n```text\n indices = [[0, 0, 1], [1, 0, 1]]\n params = [[['a0', 'b0'], ['c0', 'd0']],\n [['a1', 'b1'], ['c1', 'd1']]]\n output = ['b0', 'b1']\n```\n\n\u003cbr /\u003e\n\n\nBatched indexing into a matrix:\n\n\n```text\n indices = [[[0, 0]], [[0, 1]]]\n params = [['a', 'b'], ['c', 'd']]\n output = [['a'], ['b']]\n```\n\n\u003cbr /\u003e\n\n\nBatched slice indexing into a matrix:\n\n\n```text\n indices = [[[1]], [[0]]]\n params = [['a', 'b'], ['c', 'd']]\n output = [[['c', 'd']], [['a', 'b']]]\n```\n\n\u003cbr /\u003e\n\n\nBatched indexing into a 3-tensor:\n\n\n```text\n indices = [[[1]], [[0]]]\n params = [[['a0', 'b0'], ['c0', 'd0']],\n [['a1', 'b1'], ['c1', 'd1']]]\n output = [[[['a1', 'b1'], ['c1', 'd1']]],\n [[['a0', 'b0'], ['c0', 'd0']]]]\n```\n\n\u003cbr /\u003e\n\n\n```text\n indices = [[[0, 1], [1, 0]], [[0, 0], [1, 1]]]\n params = [[['a0', 'b0'], ['c0', 'd0']],\n [['a1', 'b1'], ['c1', 'd1']]]\n output = [[['c0', 'd0'], ['a1', 'b1']],\n [['a0', 'b0'], ['c1', 'd1']]]\n```\n\n\u003cbr /\u003e\n\n\n```text\n indices = [[[0, 0, 1], [1, 0, 1]], [[0, 1, 1], [1, 1, 0]]]\n params = [[['a0', 'b0'], ['c0', 'd0']],\n [['a1', 'b1'], ['c1', 'd1']]]\n output = [['b0', 'b1'], ['d0', 'c1']]\n```\n\n\u003cbr /\u003e\n\n\nSee also\n`\ntf.gather\n`\nand\n`\ntf.batch_gather\n`\n.\n\n\nArgs:\n\n- scope: A [Scope](/versions/r2.6/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object\n- params: The tensor from which to gather values.\n- indices: Index tensor.\n\n\u003cbr /\u003e\n\n\nReturns:\n\n- `\n `[Output](/versions/r2.6/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output)`\n ` : Values from `\n params\n ` gathered from indices given by `\n indices\n ` , with shape `\n indices.shape[:-1] + params.shape[indices.shape[-1]:]\n ` .\n\n\u003cbr /\u003e\n\n| ### Constructors and Destructors ||\n|---|---|\n| ` `[GatherNd](#classtensorflow_1_1ops_1_1_gather_nd_1a83ac49d5f8899faa1cf24f7eea2c01ac)` (const :: `[tensorflow::Scope](/versions/r2.6/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope)` & scope, :: `[tensorflow::Input](/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` params, :: `[tensorflow::Input](/versions/r2.6/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input)` indices) ` ||\n\n| ### Public attributes ||\n|---------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------|\n| ` `[operation](#classtensorflow_1_1ops_1_1_gather_nd_1a3ef794c722311cc2b178e09e32c48f15)` ` | ` `[Operation](/versions/r2.6/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation)` ` |\n| ` `[output](#classtensorflow_1_1ops_1_1_gather_nd_1a3e99a0c52482bb14c94c1bbf9b507e95)` ` | ` :: `[tensorflow::Output](/versions/r2.6/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output)` ` |\n\n| ### Public functions ||\n|-------------------------------------------------------------------------------------------------------------------------|--------------------------|\n| ` `[node](#classtensorflow_1_1ops_1_1_gather_nd_1ab32d5802ad22d9fa803952390ca3fce8)` () const ` | ` ::tensorflow::Node * ` |\n| ` `[operator::tensorflow::Input](#classtensorflow_1_1ops_1_1_gather_nd_1ab8601c2824b77c2f890a973ccd8f7212)` () const ` | ` ` |\n| ` `[operator::tensorflow::Output](#classtensorflow_1_1ops_1_1_gather_nd_1a7741e14bd7240a514268290545b62223)` () const ` | ` ` |\n\nPublic attributes\n-----------------\n\n### operation\n\n```text\nOperation operation\n``` \n\n### output\n\n```text\n::tensorflow::Output output\n``` \n\nPublic functions\n----------------\n\n### GatherNd\n\n```gdscript\n GatherNd(\n const ::tensorflow::Scope & scope,\n ::tensorflow::Input params,\n ::tensorflow::Input indices\n)\n``` \n\n### node\n\n```gdscript\n::tensorflow::Node * node() const \n``` \n\n### operator::tensorflow::Input\n\n```gdscript\n operator::tensorflow::Input() const \n``` \n\n### operator::tensorflow::Output\n\n```gdscript\n operator::tensorflow::Output() const \n```"]]