当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python tensorflow.math.unsorted_segment_max()用法及代码示例


TensorFlow是Google设计的开源Python库,用于开发机器学习模型和深度学习神经网络。

unsorted_segment_max()用于在张量的分段中找到最大元素。

用法: tensorflow.math.unsorted_segment_max(  data, segment_ids, num_segments, name )

参数:

  • data:它是张量。允许的dtypes是float32,float64,int32,uint8,int16,int8,int64,bfloat16,uint16,half,uint32,uint64。
  • segment_ids:它是带有排序值的一维张量。它的大小应等于数据一维的大小。允许的dtype是int32和int64。
  • num_segments:它是张量。允许的dtype是int32和int64。
  • name(optional):它定义了操作的名称。

返回:它返回dtype的张量作为x。



范例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.unsorted_segment_max(data, segment_ids, tf.constant(3)) 
  
# Printing the result 
print('Result:', res)

输出:

data: tf.Tensor([1 2 3], shape=(3, ), dtype=int32)
segment_ids: tf.Tensor([2 2 2], shape=(3, ), dtype=int32)
Result: tf.Tensor([-2147483648 -2147483648           3], shape=(3, ), dtype=int32)




范例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.unsorted_segment_max(data, segment_ids, tf.constant(3)) 
  
# Printing the result 
print('Result:', res)

输出:

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]
 [-2147483648 -2147483648 -2147483648]
 [          7           8           9]], shape=(3, 3), dtype=int32)



相关用法


注:本文由纯净天空筛选整理自aman neekhara大神的英文原创作品 Python – tensorflow.math.unsorted_segment_max()。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。