---
title: "scatter(withDimension:source:indices:copyFrom:reductionType:)"
framework: ML Compute
role: symbol
role_heading: Instance Method
platforms: [iOS 14.5+, iPadOS 14.5+, Mac Catalyst 14.5+, macOS 11.3+, tvOS 14.5+]
path: "mlcompute/mlcgraph/scatter(withdimension:source:indices:copyfrom:reductiontype:)"
---

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

Adds a scatter layer to the graph.

## Declaration

```swift
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

Return Value A scatter tensor.

## Discussion

Discussion The reductionType property must be MLCReductionType.none or MLCReductionType.sum.

## See Also

### Adding New Layers to Graphs

- [split(source:splitCount:dimension:)](mlcompute/mlcgraph/split(source:splitcount:dimension:).md)
- [split(source:splitSectionLengths:dimension:)](mlcompute/mlcgraph/split(source:splitsectionlengths:dimension:).md)
- [concatenate(sources:dimension:)](mlcompute/mlcgraph/concatenate(sources:dimension:).md)
- [reshape(shape:source:)](mlcompute/mlcgraph/reshape(shape:source:).md)
- [gather(withDimension:source:indices:)](mlcompute/mlcgraph/gather(withdimension:source:indices:).md)
- [transpose(dimensions:source:)](mlcompute/mlcgraph/transpose(dimensions:source:).md)
