<!--
{
  "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/gather(withDimension:source:indices:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "ML Compute"
    ],
    "preciseIdentifier" : "c:objc(cs)MLCGraph(im)gatherWithDimension:source:indices:"
  },
  "title" : "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.

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

A gather tensor.

---

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)