def moveaxis(a, source, destination): ndim = a.ndim assert (type(source) == type(destination)) source = __normal_axes(source, ndim) destination = __normal_axes(destination, ndim) assert (len(source) == len(destination)) axes = [n for n in range(ndim) if n not in source] for dest, src in sorted(zip(destination, source)): axes.insert(dest, src) return _F.transpose(a, axes)
def rollaxis(a, axis, start=0): ndim = a.ndim axis = __normal_axis(axis, ndim) start = __normal_axis(start, ndim) msg = "'%s' arg requires %d <= %s < %d, but %d was passed in" if not (0 <= start < ndim + 1): raise ValueError(msg % ('start', -ndim, 'start', ndim + 1, start)) if axis < start: start -= 1 if axis == start: return a axes = list(range(0, ndim)) axes.remove(axis) axes.insert(start, axis) return _F.transpose(a, axes)
def transpose(a, axes=None): if axes is None: axes = [i for i in reversed(range(a.ndim))] return _F.transpose(a, axes)
def swapaxes(a, axis1, axis2): axes = list(range(0, a.ndim)) axes[axis1], axes[axis2] = axes[axis2], axes[axis1] return _F.transpose(a, axes)