<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/oneHot(withIndicesTensor:depth:axis:dataType:onValue:offValue:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)oneHotWithIndicesTensor:depth:axis:dataType:onValue:offValue:name:"
  },
  "title" : "oneHot(withIndicesTensor:depth:axis:dataType:onValue:offValue:name:)"
}
-->

# oneHot(withIndicesTensor:depth:axis:dataType:onValue:offValue:name:)

Creates a oneHot operation and returns the result tensor.

```
func oneHot(withIndicesTensor indicesTensor: MPSGraphTensor, depth: Int, axis: Int, dataType: MPSDataType, onValue: Double, offValue: Double, name: String?) -> MPSGraphTensor
```

## Parameters

`indicesTensor`

Tensor of indices for on values

`depth`

Depth of the oneHot vector along the axis

`axis`

The axis to insert the new oneHot vector at. Defaults to -1, the minor axis

`dataType`

MPSDataType of the result tensor Defaults to MPSDataTypeFloat

`onValue`

The value for indices designated by the indicesTensor. This value must match the specified data type. Defaults to 1.0f

`offValue`

The value for indices not designated by the indicesTensor. This value must match the specified data type. Defaults to 0.0f

`name`

Name for the operation

## Return Value

A valid MPSGraphTensor object.

## Discussion

Creates a tensor of rank equal to the indicesTensor rank + 1.
Inserts a new axis at the axis specified, or the minor axis if axis is -1.
The values at the indices in the indicesTensor will have the onValue,
and all other values will be set to the offValue.

---

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)