<!--
{
  "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/argmax(alongAxis:keepRank:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:6CoreML8MLTensorV6argmax9alongAxis8keepRankACSi_SbtF"
  },
  "title" : "argmax(alongAxis:keepRank:)"
}
-->

# argmax(alongAxis:keepRank:)

Returns the indices of the maximum values along the specified axis.

```
func argmax(alongAxis axis: Int, keepRank: Bool = false) -> MLTensor
```

## Parameters

`axis`

The axis to reduce.

`keepRank`

A Boolean indicating whether to keep the reduced axis or not. The default value is `false`.

## Return Value

The reduced tensor.

## Discussion

```swift
let x = MLTensor(shape: [3, 2], scalars: [2, 3, 4, 5, 6, 7], scalarType: Float.self)
let y = x.argmax(alongAxis: 0)
y.shape // is [2]
y.scalarType // is Int32
await y.shapedArray(of: Int32.self) // is 2 2
```

---

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)