---
title: "init(concatenating:alongAxis:)"
framework: coreml
role: symbol
role_heading: Initializer
path: "coreml/mltensor/init(concatenating:alongaxis:)"
---

# init(concatenating:alongAxis:)

Concatenates tensors along the axis dimension.

## Declaration

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

Discussion For example: // 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:).

## See Also

### Creating a tensor

- [init(_:)](coreml/mltensor/init(_:).md)
- [init(_:alongAxis:)](coreml/mltensor/init(_:alongaxis:).md)
- [init(_:scalarType:)](coreml/mltensor/init(_:scalartype:).md)
- [init(bytesNoCopy:shape:scalarType:deallocator:)](coreml/mltensor/init(bytesnocopy:shape:scalartype:deallocator:).md)
- [init(linearSpaceFrom:through:count:)](coreml/mltensor/init(linearspacefrom:through:count:).md)
- [init(linearSpaceFrom:through:count:scalarType:)](coreml/mltensor/init(linearspacefrom:through:count:scalartype:).md)
- [init(ones:scalarType:)](coreml/mltensor/init(ones:scalartype:).md)
- [init(randomNormal:mean:standardDeviation:seed:scalarType:)](coreml/mltensor/init(randomnormal:mean:standarddeviation:seed:scalartype:).md)
- [init(randomUniform:in:seed:scalarType:)](coreml/mltensor/init(randomuniform:in:seed:scalartype:).md)
- [init(rangeFrom:to:by:)](coreml/mltensor/init(rangefrom:to:by:).md)
- [init(rangeFrom:to:by:scalarType:)](coreml/mltensor/init(rangefrom:to:by:scalartype:).md)
- [init(repeating:shape:)](coreml/mltensor/init(repeating:shape:).md)
- [init(repeating:shape:scalarType:)](coreml/mltensor/init(repeating:shape:scalartype:).md)
- [init(shape:data:scalarType:)](coreml/mltensor/init(shape:data:scalartype:).md)
- [init(shape:scalars:)](coreml/mltensor/init(shape:scalars:).md)
