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.

PR

Just a small problem.

I can fix it online!

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.sort

View Source On Gitee
mindspore.ops.sort(input_x, axis=- 1, descending=False)[source]

Sorts the elements of the input tensor along the given dimension in the specified order.

Parameters
  • input_x (Tensor) – The input tensor to sort. The shape is (N,) where means, any number of additional dimensions.

  • axis (int, optional) – The dimension to sort along. Default: -1, means the last dimension. The Ascend backend only supports sorting the last dimension.

  • descending (bool, optional) – Controls the sort order. If descending is True, the elements are sorted in descending order, or else sorted in ascending order. Default: False .

Warning

Currently, the data types of Float16, UInt8, Int8, Int16, Int32, Int64 are well supported. If use Float32, it may cause loss of accuracy.

Returns

  • y1, a tensor whose values are the sorted values, with the same shape and data type as input.

  • y2, a tensor that consists of the indices of the elements in the original input tensor. Data type is int32.

Raises
  • TypeError – If axis is not an int.

  • TypeError – If descending is not a bool.

  • TypeError – If dtype of input_x is neither float16, float32, uint8, int8, int16, int32, int64.

  • ValueError – If axis is not in range of [-len(input_x.shape), len(input_x.shape)).

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> x = Tensor(np.array([[8, 2, 1], [5, 9, 3], [4, 6, 7]]), mindspore.float16)
>>> output = ops.sort(x)
>>> # The output below is based on the Ascend platform.
>>> print(output)
(Tensor(shape=[3, 3], dtype=Float16, value=
[[ 1.0000e+00,  2.0000e+00,  8.0000e+00],
[ 3.0000e+00,  5.0000e+00,  9.0000e+00],
[ 4.0000e+00,  6.0000e+00,  7.0000e+00]]), Tensor(shape=[3, 3], dtype=Int32, value=
[[2, 1, 0],
[2, 0, 1],
[0, 1, 2]]))