<!--
{
  "availability" : [
    "iOS: 14.5.0 - 17.4.0",
    "iPadOS: 14.5.0 - 17.4.0",
    "macCatalyst: 14.5.0 - 17.4.0",
    "macOS: 11.3.0 - 14.3.0",
    "tvOS: 14.5.0 - 17.4.0"
  ],
  "documentType" : "symbol",
  "framework" : "MLCompute",
  "identifier" : "/documentation/MLCompute/MLCGraph/scatter(withDimension:source:indices:copyFrom:reductionType:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "ML Compute"
    ],
    "preciseIdentifier" : "c:objc(cs)MLCGraph(im)scatterWithDimension:source:indices:copyFrom:reductionType:"
  },
  "title" : "scatter(withDimension:source:indices:copyFrom:reductionType:)"
}
-->

# scatter(withDimension:source:indices:copyFrom:reductionType:)

Adds a scatter layer to the graph.

```
func scatter(withDimension dimension: Int, source: MLCTensor, indices: MLCTensor, copyFrom: MLCTensor, reductionType: MLCReductionType) -> MLCTensor?
```

## Parameters

`dimension`

The dimension along which to index.

`source`

The source tensor.

`indices`

The index of elements to scatter.

`copyFrom`

The source tensor whose data is first copied to the result tensor.

`reductionType`

The reduction type applied for all values in the source tensor that the system scatters to a specific location in the result tensor.

## Return Value

A scatter tensor.

## Discussion

The reductionType property must be [`MLCReductionType.none`](/documentation/MLCompute/MLCReductionType/none) or [`MLCReductionType.sum`](/documentation/MLCompute/MLCReductionType/sum).

---

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)