<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLTensor/argsort(alongAxis:descendingOrder:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:6CoreML8MLTensorV7argsort9alongAxis15descendingOrderACSi_SbtF"
  },
  "title" : "argsort(alongAxis:descendingOrder:)"
}
-->

# argsort(alongAxis:descendingOrder:)

Returns the indices (or arguments) of a tensor that give its sorted order along the specified axis.

```
func argsort(alongAxis axis: Int = -1, descendingOrder: Bool = false) -> MLTensor
```

## Parameters

`axis`

The axis along which to sort. The default is `-1`, which sorts the last axis.

`descendingOrder`

A Boolean value that determines the sort order. The default is `false` which
sorts from largest to least.

## Return Value

A `Int32` tensor of sorted indices.

## Discussion

For example:

```swift
let x = MLTensor([1.0, 3.0, 2.0])
let y = x.argSort()
await y.shapedArray(of: Int32.self) // is [0, 2, 1]
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)