codecamp

TensorFlow数学函数:tf.sparse_segment_sum

tf.sparse_segment_sum 函数

sparse_segment_sum(
    data,
    indices,
    segment_ids,
    name=None,
    num_segments=None
)

定义在:tensorflow/python/ops/math_ops.py.

请参阅指南:数学>分段

计算张量的稀疏段的和.

与 SegmentSum 类似,不同的是 segment_ids 可以有低于 data 的第一维度的秩,选择维度 0 的子集 (由索引指定).segment_ids 允许缺少 ID,在这种情况下,输出将在这些索引处为零.在这些情况下,num_segments 用于确定输出的大小.

如下示例:

c = tf.constant([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]])

# Select two rows, one segment.
tf.sparse_segment_sum(c, tf.constant([0, 1]), tf.constant([0, 0]))
# => [[0 0 0 0]]

# Select two rows, two segment.
tf.sparse_segment_sum(c, tf.constant([0, 1]), tf.constant([0, 1]))
# => [[ 1  2  3  4]
#     [-1 -2 -3 -4]]

# With missing segment ids.
tf.sparse_segment_sum(c, tf.constant([0, 1]), tf.constant([0, 2]),
                      num_segments=4)
# => [[ 1  2  3  4]
#     [ 0  0  0  0]
#     [-1 -2 -3 -4]
#     [ 0  0  0  0]]

# Select all rows, two segments.
tf.sparse_segment_sum(c, tf.constant([0, 1, 2]), tf.constant([0, 0, 1]))
# => [[0 0 0 0]
#     [5 6 7 8]]

# Which is equivalent to:
tf.segment_sum(c, tf.constant([0, 0, 1]))

函数参数:

  • data:Tensor 数据将在输出中组合.
  • indices:1 维 Tensor,索引为 data.与 segment_ids 具有相同的秩.
  • segment_ids:一个 1-D 的 Tensor,它带有索引的输出 Tensor.值应该排序并且可以重复.
  • name:操作的名称(可选).
  • num_segments:一个可选的 int32 标量.指示输出 Tensor 的大小.

函数返回值:

tf.sparse_segment_sum 函数返回作为数据的形状的一个 tensor,除了大小为 k 的维度 0 之外,它通过 num_segments 指定的段的数量或在 segments_ids 中推断最后一个元素.

TensorFlow函数:tf.sparse_segment_sqrt_n
TensorFlow函数:tf.sparse_slice
温馨提示
下载编程狮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; }