flopscope.numpy.rollaxis
fnp.rollaxis(a, axis, start=0)[flopscope source][numpy source]
Roll the specified axis backwards, until it lies in a given position.
Adapted from NumPy docs np.rollaxis
Roll specified axis backwards. Cost: numel(output).
Parameters
- a:ndarray
Input array.
- axis:int
The axis to be rolled. The positions of the other axes do not change relative to one another.
- start:int, optional
When
start <= axis, the axis is rolled back until it lies in this position. Whenstart > axis, the axis is rolled until it lies before this position. The default, 0, results in a "complete" roll. The following table describes how negative values ofstartare interpreted:table .substitution_definition⋮
Returns
- res:ndarray
For NumPy >= 1.10.0 a view of
ais always returned. For earlier NumPy versions a view ofais returned only if the order of the axes is changed, otherwise the input array is returned.
See also
- we.flops.moveaxis Move array axes to new positions.
- we.flops.roll Roll the elements of an array by a number of positions along a given axis.
Examples
>>> import flopscope.numpy as fnp
>>> a = flops.ones((3,4,5,6))
>>> flops.rollaxis(a, 3, 1).shape
(3, 6, 4, 5)
>>> flops.rollaxis(a, 2).shape
(5, 3, 4, 6)
>>> flops.rollaxis(a, 1, 4).shape
(3, 5, 6, 4)