W3cubDocs

/TensorFlow 2.3

tf.keras.backend.gather

View source on GitHub

Retrieves the elements of indices indices in the tensor reference.

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)

© 2020 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 3.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/keras/backend/gather