# tensorflow::ops::UnsortedSegmentSum Class Reference

# tensorflow::ops::UnsortedSegmentSum

`#include <math_ops.h>`

Computes the sum along segments of a tensor.

## Summary

Read [the section on segmentation](https://tensorflow.org/api_docs/python/tf/math#Segmentation) for an explanation of segments.

Computes a tensor such that \\(output\[i\] = {j...} data\[j...\]\\) where the sum is over tuples `j...` such that `segment_ids[j...] == i`. Unlike `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/segment-sum#classtensorflow_1_1ops_1_1_segment_sum`, `segment_ids` need not be sorted and need not cover all values in the full range of valid values.

If the sum is empty for a given segment ID `i`, `output[i] = 0`. If the given segment ID `i` is negative, the value is dropped and will not be added to the sum of the segment.

`num_segments` should equal the number of distinct segment IDs.


![](https://www.tensorflow.org/static/versions/r2.3/api_docs/cc/images/UnsortedSegmentSum.png)

<br />


```
c = tf.constant([[1,2,3,4], [5,6,7,8], [4,3,2,1]])
tf.unsorted_segment_sum(c, tf.constant([0, 1, 0]), num_segments=2)
# ==> [[ 5,  5, 5, 5],
#       [5,  6, 7, 8]]
```

<br />

Arguments:

- scope: A [Scope](https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope) object
- segment_ids: A tensor whose shape is a prefix of `data.shape`.

<br />

Returns:

- `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output`: Has same shape as data, except for the first `segment_ids.rank` dimensions, which are replaced with a single dimension which has size `num_segments`.

<br />

| ### Constructors and Destructors ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/unsorted-segment-sum#classtensorflow_1_1ops_1_1_unsorted_segment_sum_1a523a2af71c68956739def8e73da562ce(const ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/scope#classtensorflow_1_1_scope & scope, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input data, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input segment_ids, ::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/input#classtensorflow_1_1_input num_segments)` ||

| ### Public attributes ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/unsorted-segment-sum#classtensorflow_1_1ops_1_1_unsorted_segment_sum_1abea8a0230165d39d5462f3b026641a87` | `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/operation#classtensorflow_1_1_operation` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/unsorted-segment-sum#classtensorflow_1_1ops_1_1_unsorted_segment_sum_1ace1d27d6d7cc362c688e1a08ea92c40f` | `::https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/output#classtensorflow_1_1_output` |

| ### Public functions ||
|---|---|
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/unsorted-segment-sum#classtensorflow_1_1ops_1_1_unsorted_segment_sum_1aeb60f49f613fc351fc9cc30a55a66486() const ` | `::tensorflow::Node *` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/unsorted-segment-sum#classtensorflow_1_1ops_1_1_unsorted_segment_sum_1a11030ed77273925e7bbdf6ba24defdd9() const ` | ` `` ` |
| `https://www.tensorflow.org/versions/r2.3/api_docs/cc/class/tensorflow/ops/unsorted-segment-sum#classtensorflow_1_1ops_1_1_unsorted_segment_sum_1ac3c5ac1a7b8d9c7b5047dff05040dff1() const ` | ` `` ` |

## Public attributes

### operation

```
Operation operation
```

### output

```
::tensorflow::Output output
```

## Public functions

### UnsortedSegmentSum

```
 UnsortedSegmentSum(
  const ::tensorflow::Scope & scope,
  ::tensorflow::Input data,
  ::tensorflow::Input segment_ids,
  ::tensorflow::Input num_segments
)
```

### node

```
::tensorflow::Node * node() const 
```

### operator::tensorflow::Input

```
 operator::tensorflow::Input() const 
```

### operator::tensorflow::Output

```
 operator::tensorflow::Output() const 
```