<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Accelerate",
  "identifier" : "/documentation/Accelerate/vDSP/gather(_:indices:)-4yt3o",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Accelerate"
    ],
    "preciseIdentifier" : "s:10Accelerate4vDSPO6gather_7indicesSaySdGx_q_tAA0A6BufferRzAaGR_Sd7ElementRtzSuAHRt_r0_lFZ"
  },
  "title" : "gather(_:indices:)"
}
-->

# gather(_:indices:)

Returns a gathered copy of the specified double-precision vector using a vector that defines the indices to keep.

```
static func gather<T, U>(_ vector: T, indices: U) -> [Double] where T : AccelerateBuffer, U : AccelerateBuffer, T.Element == Double, U.Element == UInt
```

## Parameters

`vector`

The source vector that the function gathers.

`indices`

The vector that contains the one-based indices.

## Return Value

The result of the gather operation.

## Discussion

The following code shows an example of gathering the values in `source` using the values in `indices`:

```swift
let source: [Double] = [10, 20,
                        30, 40,
                        50, 60,
                        70, 80]

let indices: [UInt] = [1, 3, 5, 7]

let destination = vDSP.gather(source,
                              indices: indices)

// Prints "[10.0, 30.0, 50.0, 70.0]".
print(destination)
```

---

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)