tf.raw_ops.SparseSegmentSum
bookmark_borderbookmark
Stay organized with collections
Save and categorize content based on your preferences.
Computes the sum along sparse segments of a tensor.
View aliases
Compat aliases for migration
See
Migration guide for
more details.
tf.compat.v1.raw_ops.SparseSegmentSum
tf.raw_ops.SparseSegmentSum(
data, indices, segment_ids, sparse_gradient=False, name=None
)
Read
the section on segmentation
for an explanation of segments.
Like SegmentSum
, but segment_ids
can have rank less than data
's first
dimension, selecting a subset of dimension 0, specified by indices
.
For example:
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]]
# 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]))
Args |
data
|
A Tensor . Must be one of the following types: float32 , float64 , int32 , uint8 , int16 , int8 , int64 , bfloat16 , uint16 , half , uint32 , uint64 .
|
indices
|
A Tensor . Must be one of the following types: int32 , int64 .
A 1-D tensor. Has same rank as segment_ids .
|
segment_ids
|
A Tensor . Must be one of the following types: int32 , int64 .
A 1-D tensor. Values should be sorted and can be repeated.
|
sparse_gradient
|
An optional bool . Defaults to False .
|
name
|
A name for the operation (optional).
|
Returns |
A Tensor . Has the same type as data .
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.raw_ops.SparseSegmentSum\n\n\u003cbr /\u003e\n\nComputes the sum along sparse segments of a tensor.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.raw_ops.SparseSegmentSum`](https://www.tensorflow.org/api_docs/python/tf/raw_ops/SparseSegmentSum)\n\n\u003cbr /\u003e\n\n tf.raw_ops.SparseSegmentSum(\n data, indices, segment_ids, sparse_gradient=False, name=None\n )\n\nRead\n[the section on segmentation](https://tensorflow.org/api_docs/python/tf/math#Segmentation)\nfor an explanation of segments.\n\nLike `SegmentSum`, but `segment_ids` can have rank less than `data`'s first\ndimension, selecting a subset of dimension 0, specified by `indices`.\n\n#### For example:\n\n c = tf.constant([[1,2,3,4], [-1,-2,-3,-4], [5,6,7,8]])\n\n # Select two rows, one segment.\n tf.sparse_segment_sum(c, tf.constant([0, 1]), tf.constant([0, 0]))\n # =\u003e [[0 0 0 0]]\n\n # Select two rows, two segment.\n tf.sparse_segment_sum(c, tf.constant([0, 1]), tf.constant([0, 1]))\n # =\u003e [[ 1 2 3 4]\n # [-1 -2 -3 -4]]\n\n # Select all rows, two segments.\n tf.sparse_segment_sum(c, tf.constant([0, 1, 2]), tf.constant([0, 0, 1]))\n # =\u003e [[0 0 0 0]\n # [5 6 7 8]]\n\n # Which is equivalent to:\n tf.segment_sum(c, tf.constant([0, 0, 1]))\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data` | A `Tensor`. Must be one of the following types: `float32`, `float64`, `int32`, `uint8`, `int16`, `int8`, `int64`, `bfloat16`, `uint16`, `half`, `uint32`, `uint64`. |\n| `indices` | A `Tensor`. Must be one of the following types: `int32`, `int64`. A 1-D tensor. Has same rank as `segment_ids`. |\n| `segment_ids` | A `Tensor`. Must be one of the following types: `int32`, `int64`. A 1-D tensor. Values should be sorted and can be repeated. |\n| `sparse_gradient` | An optional `bool`. Defaults to `False`. |\n| `name` | A name for the operation (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor`. Has the same type as `data`. ||\n\n\u003cbr /\u003e"]]