<!--
{
  "availability" : [
    "iOS: 15.4.0 -",
    "iPadOS: 15.4.0 -",
    "macCatalyst: 15.4.0 -",
    "macOS: 12.3.0 -",
    "tvOS: 15.4.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalPerformanceShadersGraph",
  "identifier" : "/documentation/MetalPerformanceShadersGraph/MPSGraph/scatterAlongAxisTensor(_:data:updates:indices:mode:name:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Metal Performance Shaders Graph",
      "MetalPerformanceShadersGraph"
    ],
    "preciseIdentifier" : "c:objc(cs)MPSGraph(im)scatterAlongAxisTensor:withDataTensor:updatesTensor:indicesTensor:mode:name:"
  },
  "title" : "scatterAlongAxisTensor(_:data:updates:indices:mode:name:)"
}
-->

# scatterAlongAxisTensor(_:data:updates:indices:mode:name:)

Creates a ScatterAlongAxis operation and returns the result tensor.

```
func scatterAlongAxisTensor(_ axisTensor: MPSGraphTensor, data dataTensor: MPSGraphTensor, updates updatesTensor: MPSGraphTensor, indices indicesTensor: MPSGraphTensor, mode: MPSGraphScatterMode, name: String?) -> MPSGraphTensor
```

## Parameters

`axisTensor`

Scalar Int32 tensor. The axis to scatter to. Negative values wrap around

`dataTensor`

The input tensor to scatter values onto

`updatesTensor`

The input tensor to scatter values from

`indicesTensor`

Int32 or Int64 tensor used to index the result tensor.

`mode`

The type of update to use

`name`

The name for the operation.

## Return Value

A valid MPSGraphTensor object

## Discussion

Scatter values from `updatesTensor` along the specified `axis` at indices in `indicesTensor` onto `dataTensor`.
Values in `dataTensor` are updated following `mode`. See MPSGraphScatterMode.
The shape of `updatesTensor` and `indicesTensor` must match. The shape of `dataTensor` must match except at `axis`.
If an index is out of bounds of `shape` along `axis` the update value is skipped.
For example,

```md
data = [ [0, 0, 0],
         [1, 1, 1],
         [2, 2, 2],
         [3, 3, 3] ]
updates = [ [1, 2, 3],
            [4, 5, 6] ]
indices = [ [2, 1, 0],
            [1, 3, 2] ]
axis = 0
result = scatterAlongAxis(axis, data, updates, indices, MPSGraphScatterModeAdd, "scatter")
result = [ [0, 0, 3],
           [5, 3, 1],
           [3, 2, 8],
           [3, 8, 3] ]
```

---

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)