pydsm.relab.shiftdim¶
-
pydsm.relab.
shiftdim
(x, n=None, nargout=2)¶ Shift dimensions a la Matlab
When n is provided, shiftdim shifts the axes of x by n. If n is positive, it shifts the axes to the left, wrapping the leading axes with non unitary length to the end. When n is negative, it shifts the axes to the right, inserting n leading axes with unitary length. When n is not provided or None, it shifts the axes to the left, reducing the number of dimensions and removing all the leading axes with unitary length.
- Parameters
- xarray like
multi-dimensional array to operate upon
- nint or None, optional
amount to shift. Defaults to None, which means automatic computation
- nargoutint
number of output values
- Returns
- yndarray
the result of the axes shift operation
- nint
the actual shift
Examples
>>> from numpy.random import rand >>> a = rand(1, 1, 3, 1, 2) >>> b, n = shiftdim(a) >>> b.shape (3, 1, 2) >>> n 2 >>> c = shiftdim(b, -n, nargout=1) >>> np.alltrue(c == a) True >>> d = shiftdim(a, 3, nargout=1) >>> d.shape (1, 2, 1, 1, 3)
>>> b, n = shiftdim([[[1]]]) >>> b, n (array([[[1]]]), 0)