tf.keras.backend.gather
Stay organized with collections
Save and categorize content based on your preferences.
Retrieves the elements of indices indices
in the tensor reference
.
tf.keras.backend.gather(
reference, indices
)
Arguments |
reference
|
A tensor.
|
indices
|
An integer tensor of indices.
|
Returns |
A tensor of same type as reference .
|
Examples:
var = tf.keras.backend.variable([[1, 2, 3], [4, 5, 6]])
tf.keras.backend.eval(var)
array([[1., 2., 3.],
[4., 5., 6.]], dtype=float32)
var_gathered = tf.keras.backend.gather(var, [0])
tf.keras.backend.eval(var_gathered)
array([[1., 2., 3.]], dtype=float32)
var_gathered = tf.keras.backend.gather(var, [1])
tf.keras.backend.eval(var_gathered)
array([[4., 5., 6.]], dtype=float32)
var_gathered = tf.keras.backend.gather(var, [0,1,0])
tf.keras.backend.eval(var_gathered)
array([[1., 2., 3.],
[4., 5., 6.],
[1., 2., 3.]], dtype=float32)
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.
Last updated 2020-10-01 UTC.
[null,null,["Last updated 2020-10-01 UTC."],[],[],null,["# tf.keras.backend.gather\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/keras/backend/gather) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.3.0/tensorflow/python/keras/backend.py#L2056-L2086) |\n\nRetrieves the elements of indices `indices` in the tensor `reference`.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.keras.backend.gather`](/api_docs/python/tf/keras/backend/gather)\n\n\u003cbr /\u003e\n\n tf.keras.backend.gather(\n reference, indices\n )\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Arguments --------- ||\n|-------------|-------------------------------|\n| `reference` | A tensor. |\n| `indices` | An integer tensor of indices. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A tensor of same type as `reference`. ||\n\n\u003cbr /\u003e\n\n#### Examples:\n\n var = tf.keras.backend.variable([[1, 2, 3], [4, 5, 6]])\n tf.keras.backend.eval(var)\n array([[1., 2., 3.],\n [4., 5., 6.]], dtype=float32)\n var_gathered = tf.keras.backend.gather(var, [0])\n tf.keras.backend.eval(var_gathered)\n array([[1., 2., 3.]], dtype=float32)\n var_gathered = tf.keras.backend.gather(var, [1])\n tf.keras.backend.eval(var_gathered)\n array([[4., 5., 6.]], dtype=float32)\n var_gathered = tf.keras.backend.gather(var, [0,1,0])\n tf.keras.backend.eval(var_gathered)\n array([[1., 2., 3.],\n [4., 5., 6.],\n [1., 2., 3.]], dtype=float32)"]]