codecamp

TensorFlow函数:tf.unsorted_segment_sum

tf.unsorted_segment_sum函数

tf.unsorted_segment_sum(
    data,
    segment_ids,
    num_segments,
    name=None
)

请参阅指南:数学函数>分段

计算张量片段的和.

计算一个张量,使得 (output[i] = sum_{j...} data[j...] 总和超过元组 j...,例如,segment_ids[j...] == i.与 SegmentSum 不同,segment_ids 不需要排序,不需要覆盖整个有效值范围内的所有值.

如果给定段 ID i 的和为空,则 output[i] = 0.如果给定的分段 ID i 为负值,则该值将被删除并且不会被添加到该段的总和中.

num_segments 应等于不同的段 ID 的数量.

TensorFlow函数

函数参数:

  • data:一个 Tensor,必须是下列类型之一:float32,float64,int32,uint8,int16,int8,complex64,int64,qint8,quint8,qint32,bfloat16,uint16,complex128,half,uint32,uint64.
  • segment_ids:一个 Tensor,必须是以下类型之一:int32,int64,张量的形状是一个 data.shape 的前缀.
  • num_segments:一个 Tensor,必须是以下类型之一:int32,int64.
  • name:操作的名称(可选).

函数返回值:

tf.unsorted_segment_sum函数返回一个 Tensor,它与 data 的类型相同.


例子:

a = np.arange(1,10).reshape(3,3)

print(a)

print('----------')

print((sess.run(tf.unsorted_segment_sum(data=a,segment_ids=[0,1,0],num_segments=2))))


输出:

[[1 2 3]

 [4 5 6]

 [7 8 9]]

----------

[[ 8 10 12]

 [ 4  5  6]



TensorFlow函数:tf.unsorted_segment_max
TensorFlow函数:tf.unstack
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

TensorFlow 函数介绍

TensorFlow 函数模块:tf

TensorFlow的image模块

TensorFlow使用之tf.io

TensorFlow使用之tf.keras

TensorFlow函数教程:tf.keras.applications

TensorFlow函数教程:tf.keras.backend

TensorFlow使用之tf.metrics

TensorFlow使用之tf.nn

TensorFlow使用之tf.python_io

TensorFlow 功能函数

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }