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

# init(stacking:alongAxis:)

Stacks the given tensors along the axis dimension into a new tensor with rank one higher than the current tensor and each tensor.

## Declaration

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

## Parameters

- `tensors`: The tensors to stack. All tensors must have the same shape and scalar type.
- `axis`: The axis along which to stack. Negative values wrap around but must be in the range [-rank, rank], where rank is the rank of the provided tensors.

## Discussion

Discussion Given that tensors all have shape [A, B, C], and tensors.count = N, then: if axis == 0 then the resulting tensor will have the shape [N, A, B, C]. if axis == 1 then the resulting tensor will have the shape [A, N, B, C]. etc. For example: // 'x' is [1, 4] // 'y' is [2, 5] // 'z' is [3, 6] MLTensor(stacking: [x, y, z]) // is [[1, 4], [2, 5], [3, 6]] MLTensor(stacking: [x, y, z], alongAxis: 1) // is [[1, 2, 3], [4, 5, 6]]

## 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(concatenating:alongAxis:)](coreml/mltensor/init(concatenating:alongaxis:).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)
