Python - tensorflow.gather() Last Updated : 07 Mar, 2023 Comments Improve Suggest changes Like Article Like Report TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. gather() is used to slice the input tensor based on the indices provided. Syntax: tensorflow.gather( params, indices, validate_indices, axis, batch_dims, name) Parameters: params: It is a Tensor with rank greater than or equal to axis+1.indices: It is a Tensor of dtype int32 or int64. It's value should be in range [0, params.shape[axis]).axis: It is a Tensor of dtype int32 or int64. It defines the axis from which indices should be gathered. Default value is 0 and it must be greater than or equal to batch_dims.batch_dims: It is an integer representing the number o batch dimension. It must be less than or equal to rank(indices).name: It defines the name for the operation. Returns: It returns a Tensor having same dtype as param. Example 1: Python3 # Importing the library import tensorflow as tf # Initializing the input data = tf.constant([1, 2, 3, 4, 5, 6]) indices = tf.constant([0, 1, 2, 1]) # Printing the input print('data: ',data) print('indices: ',indices) # Calculating result res = tf.gather(data, indices) # Printing the result print('res: ',res) Output: data: tf.Tensor([1 2 3 4 5 6], shape=(6,), dtype=int32) indices: tf.Tensor([0 1 2 1], shape=(4,), dtype=int32) res: tf.Tensor([1 2 3 2], shape=(4,), dtype=int32) Example 2: Python3 # Importing the library import tensorflow as tf # Initializing the input data = tf.constant([[1, 2], [3, 4], [5, 6]]) indices = tf.constant([2, 0, 1]) # Printing the input print('data: ',data) print('indices: ',indices) # Calculating result res = tf.gather(data, indices) # Printing the result print('res: ',res) Output: data: tf.Tensor( [[1 2] [3 4] [5 6]], shape=(3, 2), dtype=int32) indices: tf.Tensor([2 0 1], shape=(3,), dtype=int32) res: tf.Tensor( [[5 6] [1 2] [3 4]], shape=(3, 2), dtype=int32) Comment More infoAdvertise with us Next Article Python - tensorflow.gather() aman neekhara Follow Improve Article Tags : Python Python-Tensorflow Python Tensorflow-math-functions Practice Tags : python Similar Reads Python - tensorflow.gather_nd() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. gather_nd() is used to gather the slice from input tensor based on the indices provided. Syntax: tensorflow.gather_nd( params, indices, batch_dims, name) Parameters: pa 2 min read Python - tensorflow.eye() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. tensorflow.eye() is used to generate identity matrix. Syntax: tensorflow.eye( num_rows, num_columns, batch_shape, dtype, name) Parameters: num_rows: It is int32 scalar 2 min read Python - tensorflow.concat() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. concat() is used to concatenate tensors along one dimension. Syntax: tensorflow.concat( values, axis, name ) Parameter: values: It is a tensor or list of tensor.axis: It 2 min read Python - tensorflow.identity() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. identity() returns a Tensor with the same shape and contents as input. Syntax: tensorflow.identity(input, name) Parameters: input: It is a Tensor.name(optional): It def 2 min read Python - tensorflow.identity_n() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. identity_n() is used get a list of Tensor with same shape and content as input Tensor. Syntax: tensorflow.identity_n( input, name) Parameters: input:  It is a Tensor.na 2 min read Python - tensorflow.constant_initializer() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. constant_initializer() is initializer that generate a Tensor with constant value. Syntax: tensorflow.constant_initializer( value ) Parameters: value: It is the value tha 1 min read Python - tensorflow.clip_by_global_norm() <p><a href="https://www.geeksforgeeks.org/introduction-to-tensorflow/">TensorFlow</a> is open-source python library designed by Google to develop Machine Learning models and deep learning  neural networks. clip_by_global_norm() is used to clip values of multiple tensors by the rati 2 min read Python - tensorflow.IndexedSlices() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. IndexedSlices() is used to find the sparse representation of a set of tensor slices at given indices. Syntax: tensorflow.IndexedSlices(values, indices, dense_shape = No 1 min read Python - tensorflow.dynamic_stitch() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. dynamic_stitch() is used to merge multiple tensors into single tensor. Syntax: tensorflow.dynamic_stitch( indices, data, name) Parameter: indices: It is a list of Tensor 2 min read Python - tensorflow.dynamic_partition() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. dynamic_partition()  is used to divide the data into number of partitions. Syntax: tensorflow.dynamic_partition(data, partitions, num_partitions, name) Parameters: data 2 min read Like