<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreML",
  "identifier" : "/documentation/CoreML/MLTensor/init(concatenating:alongAxis:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core ML",
      "CoreML"
    ],
    "preciseIdentifier" : "s:6CoreML8MLTensorV13concatenating9alongAxisACx_SitcSlRzAC7ElementRtzlufc"
  },
  "title" : "init(concatenating:alongAxis:)"
}
-->

# init(concatenating:alongAxis:)

Concatenates `tensors` along the `axis` dimension.

```
init(concatenating tensors: some Collection<MLTensor>, alongAxis axis: Int = 0)
```

## Parameters

`tensors`

The tensors to concatenate. All tensors must have the same rank and all dimensions except `axis` must be equal.

`axis`

The axis along which to concatenate. Negative values wrap around but must be in the range `[-rank, rank)`, where
`rank` is the rank of the provided tensors.

## Discussion

For example:

```swift
// t1 is [[1, 2, 3], [4, 5, 6]]
// t2 is [[7, 8, 9], [10, 11, 12]]
MLTensor(concatenating: [t1, t2]) // is [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]]
MLTensor(concatenating: [t1, t2], alongAxis: 1) // is [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]]

// t3 has shape [2, 3]
// t4 has shape [2, 3]
MLTensor(concatenating: [t3, t4]) // has shape [4, 3]
MLTensor(concatenating: [t3, t4], alongAxis: 1) // has shape [2, 6]
```

> Note: If you are concatenating along a new axis consider using
> `MLTensor(stacking:alongAxis:)`.

---

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)