Python - tensorflow.math.segment_max() Last Updated : 12 Jun, 2020 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. segment_max() is used to find the maximum element in segments of a tensor. Syntax: tensorflow.math.segment_max( data, segment_ids, name ) Parameter: data: It is a tensor. Allowed dtypes are float32, float64, int32, uint8, int16, int8, int64, bfloat16, uint16, half, uint32, uint64.segment_ids: It's 1-D tensor with sorted values. It's size should be equal to size of first dimension of data. Allowed dtypes are int32 and int64.name(optional): It defines the name for the operation. Return: It returns a tensor of dtype as x. Example 1: Python3 # importing the library import tensorflow as tf # Initializing the input tensor data = tf.constant([1, 2, 3]) segment_ids = tf.constant([2, 2, 2]) # Printing the input tensor print('data: ', data) print('segment_ids: ', segment_ids) # Calculating result res = tf.math.segment_max(data, segment_ids) # Printing the result print('Result: ', res) Output: data: tf.Tensor([1 2 3], shape=(3, ), dtype=int32) segment_ids: tf.Tensor([2 2 2], shape=(3, ), dtype=int32) Result: tf.Tensor([0 0 3], shape=(3, ), dtype=int32) Example 2: Python3 # importing the library import tensorflow as tf # Initializing the input tensor data = tf.constant([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) segment_ids = tf.constant([0, 0, 2]) # Printing the input tensor print('data: ', data) print('segment_ids: ', segment_ids) # Calculating result res = tf.math.segment_max(data, segment_ids) # Printing the result print('Result: ', res) Output: data: tf.Tensor( [[1 2 3] [4 5 6] [7 8 9]], shape=(3, 3), dtype=int32) segment_ids: tf.Tensor([0 0 2], shape=(3, ), dtype=int32) Result: tf.Tensor( [[4 5 6] [0 0 0] [7 8 9]], shape=(3, 3), dtype=int32) Comment More infoAdvertise with us Next Article Python - tensorflow.math.segment_max() A aman neekhara Follow Improve Article Tags : Machine Learning AI-ML-DS With Python Practice Tags : Machine Learning Similar Reads Python - tensorflow.math.segment_mean() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. segment_mean() is used to find the mean of elements in segments of a tensor. Syntax: tensorflow.math.segment_mean( data, segment_ids, name ) Parameter: data: It is a tens 2 min read Python - tensorflow.math.segment_min() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. segment_min() is used to find the minimum element in segments of a tensor. Syntax: tensorflow.math.segment_min( data, segment_ids, name ) Parameter: data: It is a tensor. 2 min read Python - tensorflow.math.segment_prod() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. segment_prod() is used to find the product of elements in segments of a tensor. Syntax: tensorflow.math.segment_prod( data, segment_ids, name ) Parameter: data: It is a t 2 min read Python - tensorflow.math.unsorted_segment_max() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. unsorted_segment_max() is used to find the maximum element in segments of a tensor. Syntax: tensorflow.math.unsorted_segment_max( data, segment_ids, num_segments, name ) 2 min read Python - tensorflow.math.segment_sum() TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks. segment_sum() is used to find the sum of elements in segments of a tensor. Syntax: tensorflow.math.segment_sum( data, segment_ids, name ) Parameter: data: It is a tensor. 2 min read Like