bundles / numpy latest / numpy / unstack
_ArrayFunctionDispatcher
numpy:unstack
source: /dev/numpy/build-install/usr/lib/python3.14/site-packages/numpy/_core/shape_base.py :471
Signature
def unstack ( x , / , axis = 0 ) Summary
Split an array into a sequence of arrays along the given axis.
Extended Summary
The axis parameter specifies the dimension along which the array will be split. For example, if axis=0 (the default) it will be the first dimension and if axis=-1 it will be the last dimension.
The result is a tuple of arrays split along axis.
Parameters
x: ndarrayThe array to be unstacked.
axis: int, optionalAxis along which the array will be split. Default:
0.
Returns
unstacked: tuple of ndarraysThe unstacked arrays.
Notes
unstack serves as the reverse operation of stack, i.e., stack(unstack(x, axis=axis), axis=axis) == x.
This function is equivalent to tuple(np.moveaxis(x, axis, 0)), since iterating on an array iterates along the first axis.
Examples
arr = np.arange(24).reshape((2, 3, 4))
✓np.unstack(arr) np.unstack(arr, axis=1)✗
arr2 = np.stack(np.unstack(arr, axis=1), axis=1) arr2.shape np.all(arr == arr2)✓
See also
- block
Assemble an nd-array from nested lists of blocks.
- concatenate
Join a sequence of arrays along an existing axis.
- split
Split array into a list of multiple sub-arrays of equal size.
- stack
Join a sequence of arrays along a new axis.
Aliases
-
numpy.unstack