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
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], whererankis the rank of the provided tensors.
Discussion
Given that tensors all have shape [A, B, C], and tensors.count = N, then:
if
axis == 0then the resulting tensor will have the shape[N, A, B, C].if
axis == 1then 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(_:)init(_:alongAxis:)init(_:scalarType:)init(bytesNoCopy:shape:scalarType:deallocator:)init(concatenating:alongAxis:)init(linearSpaceFrom:through:count:)init(linearSpaceFrom:through:count:scalarType:)init(ones:scalarType:)init(randomNormal:mean:standardDeviation:seed:scalarType:)init(randomUniform:in:seed:scalarType:)init(rangeFrom:to:by:)init(rangeFrom:to:by:scalarType:)init(repeating:shape:)init(repeating:shape:scalarType:)init(shape:data:scalarType:)