Computes the sum along sparse segments of a tensor.
tf.raw_ops.SparseSegmentSumWithNumSegments(
data, indices, segment_ids, num_segments, sparse_gradient=False, name=None
)
Like SparseSegmentSum
, but allows missing ids in segment_ids
. If an id is
missing, the output
tensor at that position will be zeroed.
Read the section on segmentation for an explanation of segments.
For example:
c = tf.constant([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]])
tf.sparse_segment_sum_with_num_segments(
c, tf.constant([0, 1]), tf.constant([0, 0]), num_segments=3)
# => [[0 0 0 0]
# [0 0 0 0]
# [0 0 0 0]]
tf.sparse_segment_sum_with_num_segments(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]]
Returns | |
---|---|
A Tensor . Has the same type as data .
|