mindspore.ops.UnsortedSegmentSum
- class mindspore.ops.UnsortedSegmentSum[source]
Computes the sum of a tensor along segments.
Refer to
mindspore.ops.unsorted_segment_sum()
for more details.- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> from mindspore import Tensor >>> from mindspore import ops >>> import mindspore >>> input_x = Tensor([1, 2, 3, 4], mindspore.float32) >>> segment_ids = Tensor([0, 0, 1, 2], mindspore.int32) >>> num_segments = 4 >>> output = ops.UnsortedSegmentSum()(input_x, segment_ids, num_segments) >>> print(output) [3. 3. 4. 0.] >>> input_x = Tensor([1, 2, 3, 4, 2, 5], mindspore.float32) >>> segment_ids = Tensor([0, 0, 1, 2, 3, 4], mindspore.int32) >>> num_segments = 6 >>> output = ops.UnsortedSegmentSum()(input_x, segment_ids, num_segments) >>> print(output) [3. 3. 4. 2. 5. 0.]