---
title: "gather(withDimension:source:indices:)"
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/gather(withdimension:source:indices:)"
---

# gather(withDimension:source:indices:)

Adds a gather layer to the graph using the source tensor, dimension along which to index, and the indices you specify.

## Declaration

```swift
func gather(withDimension dimension: Int, source: MLCTensor, indices: MLCTensor) -> MLCTensor?
```

## Parameters

- `dimension`: The dimension along which to index.
- `source`: The source tensor.
- `indices`: The index of elements to gather.

## Return Value

Return Value A gather tensor.

## 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)
- [scatter(withDimension:source:indices:copyFrom:reductionType:)](mlcompute/mlcgraph/scatter(withdimension:source:indices:copyfrom:reductiontype:).md)
- [transpose(dimensions:source:)](mlcompute/mlcgraph/transpose(dimensions:source:).md)
