argsort(alongAxis:descendingOrder:)
Returns the indices (or arguments) of a tensor that give its sorted order along the specified axis.
Declaration
func argsort(alongAxis axis: Int = -1, descendingOrder: Bool = false) -> MLTensorParameters
- 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
falsewhich sorts from largest to least.
Return Value
A Int32 tensor of sorted indices.
Discussion
For example:
let x = MLTensor([1.0, 3.0, 2.0])
let y = x.argSort()
await y.shapedArray(of: Int32.self) // is [0, 2, 1]