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

# init(concatenating:alongAxis:)

Merges a sequence of shaped arrays into one shaped array along an axis.

```
init<S>(concatenating shapedArrays: S, alongAxis: Int) where Scalar == S.Element.Scalar, S : Sequence, S.Element : MLShapedArrayProtocol
```

## Parameters

`shapedArrays`

A sequence of shaped arrays.

`alongAxis`

A zero-based axis number the shaped arrays in `multiArray` merge along.
  
  > Tip:
  > Select the shaped array’s highest dimension by passing a negative axis number. For example, an axis value of `-1` or `-2` selects the last or second-to-last dimension, respectively.

## Discussion

All shaped arrays in the sequence must have the following:

- The same underlying data type
- The same number of dimensions
- The same size for each corresponding dimension, except for the concatenation axis

For example, this code concatenates two shaped arrays along their second dimension:

```swift
// A 2x3 shaped array.
// 0 1 2
// 5 6 7
let shapedArray1 = MLShapedArray<Int32>(scalars: [0, 1, 2, 5, 6, 7],
                                        shape: [2, 3])

// A 2x2 shaped array.
// 3 4
// 8 9
let shapedArray2 = MLShapedArray<Int32>(scalars: [3, 4, 8, 9],
                                        shape: [2, 2])

// A 2x5 shaped array.
// 0 1 2 3 4
// 5 6 7 8 9
let shapedArray3 = MLShapedArray(concatenating: [shapedArray1,shapedArray2],
                                 alongAxis: 1)
```

---

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)