Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.sparse_segment_mean

mindspore.ops.sparse_segment_mean(x, indices, segment_ids)[source]

Computes a Tensor such that outputi=jxindices[j]N where mean is over j such that segment_ids[j]==i and N is the total number of values summed. If the mean is empty for a given segment ID i, output[i]=0.

Note

  • On CPU, values in segment_ids are always validated to be sorted, and an error is thrown for indices that are not increasing. Moreover, values in indices are validated to be bounded, and an error is thrown when indices are out of range[0, x.shape[0]).

  • On GPU, this does not throw an error for unsorted segment_ids and out-of-bound indices. Out-of-order segment_ids result in safe but unspecified behavior, while out-of-range indices will be ignored.

Parameters
  • x (Tensor) – A Tensor, and its rank must be greater than or equal to 1.

  • indices (Tensor) – A 1-D Tensor, with int32 or int64 data type.

  • segment_ids (Tensor) – A 1-D Tensor, must have the same dtype as indices. Values should be sorted and can be repeated.

Returns

Tensor, whose dtype and rank is the same as x. The first dimension is equal to the value of the last element of segment_ids plus one, and the other dimensions are the same as those of x.

Raises
  • TypeError – If x, indices or segment_ids is not a Tensor.

  • TypeError – If the dtype of x is not one of the following dtype: float16, float32, float64.

  • TypeError – If the dtype of indices and segment_ids are not one of the following dtype: int32, int64.

  • TypeError – If the dtype of indices and segment_ids are not the same.

  • ValueError – If the shape of x, indices or segment_ids don't meet the parameter description.

  • ValueError – If the size of indices and segment_ids are not the same.

Supported Platforms:

GPU CPU

Examples

>>> import mindspore
>>> from mindspore import Tensor, ops
>>> x = Tensor([[0, 1, 2], [1, 2, 3], [3, 6, 7]], dtype=mindspore.float32)
>>> indices = Tensor([0, 1, 2], dtype=mindspore.int32)
>>> segment_ids = Tensor([1,2,2], dtype=mindspore.int32)
>>> out = ops.sparse_segment_mean(x, indices, segment_ids)
>>> print(out)
[[0. 0. 0.]
 [0. 1. 2.]
 [2. 4. 5.]]