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.fingerprint() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. fingerprint() is used to generate fingerprint value. Syntax: tensorflow.fingerprint( data, method, name) Parameters: data: It is a Tensor having rank 1 or higher.method 2 min read Python - tensorflow.fill() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. fill() is used to generate a tensor having scalar value. Syntax: tensorflow.fill( dims, value, name) Parameters: dims: It is 1-D sequence of dtype int32 or int64 with n 2 min read Python - tensorflow.cond() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks. cond() return true_fn() if the predicate pred is true otherwise it returns false_fn(). Syntax: tensorflow.cond( pred, true_fn, false_fn, name ) Parameters: pred: It is a 1 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.argsort() method TensorFlow is open-source python library designed by Google to develop Machine Learning models  and deep learning  neural networks. Tensorflow have a method argsort() which is used to find the indices of a Tensor in sorted order. Syntax: tf.argsort(values, axis, direction, stable, name) Parameters: 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.raw_ops.Acosh() TensorFlow is open-source python library designed by Google to develop Machine Learning models and deep learning  neural networks. TensorFlow raw_ops provides low level access to all TensorFlow operations. Acosh() is used to find element wise inverse hyperbolic cosine of x. Syntax: tf.raw_ops.Acosh( 1 min read Like