MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / gather_nd

Function gather_nd

tensorflow/python/ops/array_ops.py:4130–4291  ·  view source on GitHub ↗

r"""Gather slices from `params` into a Tensor with shape specified by `indices`. `indices` is an 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}\\)] = param

(params, indices, name=None, batch_dims=0)

Source from the content-addressed store, hash-verified

4128@dispatch.add_dispatch_support
4129@deprecated_endpoints("manip.gather_nd")
4130def gather_nd(params, indices, name=None, batch_dims=0):
4131 r"""Gather slices from `params` into a Tensor with shape specified by `indices`.
4132
4133 `indices` is an K-dimensional integer tensor, best thought of as a
4134 (K-1)-dimensional tensor of indices into `params`, where each element defines
4135 a slice of `params`:
4136
4137 output[\\(i_0, ..., i_{K-2}\\)] = params[indices[\\(i_0, ..., i_{K-2}\\)]]
4138
4139 Whereas in `tf.gather` `indices` defines slices into the first
4140 dimension of `params`, in `tf.gather_nd`, `indices` defines slices into the
4141 first `N` dimensions of `params`, where `N = indices.shape[-1]`.
4142
4143 The last dimension of `indices` can be at most the rank of
4144 `params`:
4145
4146 indices.shape[-1] <= params.rank
4147
4148 The last dimension of `indices` corresponds to elements
4149 (if `indices.shape[-1] == params.rank`) or slices
4150 (if `indices.shape[-1] < params.rank`) along dimension `indices.shape[-1]`
4151 of `params`. The output tensor has shape
4152
4153 indices.shape[:-1] + params.shape[indices.shape[-1]:]
4154
4155 Additionally both 'params' and 'indices' can have M leading batch
4156 dimensions that exactly match. In this case 'batch_dims' must be M.
4157
4158 Note that on CPU, if an out of bound index is found, an error is returned.
4159 On GPU, if an out of bound index is found, a 0 is stored in the
4160 corresponding output value.
4161
4162 Some examples below.
4163
4164 Simple indexing into a matrix:
4165
4166 ```python
4167 indices = [[0, 0], [1, 1]]
4168 params = [['a', 'b'], ['c', 'd']]
4169 output = ['a', 'd']
4170 ```
4171
4172 Slice indexing into a matrix:
4173
4174 ```python
4175 indices = [[1], [0]]
4176 params = [['a', 'b'], ['c', 'd']]
4177 output = [['c', 'd'], ['a', 'b']]
4178 ```
4179
4180 Indexing into a 3-tensor:
4181
4182 ```python
4183 indices = [[1]]
4184 params = [[['a0', 'b0'], ['c0', 'd0']],
4185 [['a1', 'b1'], ['c1', 'd1']]]
4186 output = [[['a1', 'b1'], ['c1', 'd1']]]
4187

Callers 1

gather_nd_v2Function · 0.70

Calls 2

batch_gather_ndFunction · 0.85
gather_ndMethod · 0.45

Tested by

no test coverage detected