unstacked(alongAxis:)
Unpacks the given dimension of a rank-R tensor into multiple rank-(R-1) tensors.
Declaration
func unstacked(alongAxis axis: Int = 0) -> [MLTensor]Parameters
- axis:
The dimension along which to unstack. The
axismust be in the range[-rank, rank).
Return Value
An array containing the unstacked tensors.
Discussion
Unpacks N tensors from this tensor by chipping it along the axis dimension, where N is inferred from this tensor’s shape. For example, given a tensor with shape [A, B, C, D]:
If
axis == 0then thei-th tensor in the returned array is the sliceself[i, nil, nil, nil]and each tensor in that array will have shape[B, C, D].If
axis == 1then thei-th tensor in the returned array is the slicevalue[:, i, :, :]and each tensor in that array will have shape[A, C, D].Etc.
This is the opposite of MLTensor.init(stacking:alongAxis:).