dimshuffle equivalent function in Numpy dimshuffle equivalent function in Numpy numpy numpy

dimshuffle equivalent function in Numpy


The function numpy.transpose permits any permutation of the axes of an array.

The variety array.T is a special case of this, corresponding to array.transpose() without arguments, which defaults to array.transpose(range(array.ndim)[::-1]).

numpy.swapaxes is numpy.transpose restricted to permutations of two axes.

theano.tensor.dimshuffle essentially corresponds to numpy.transpose, but in addition, it permits the creation of new axes of length 1 for broadcasting, by adding 'x' wherever an axis should be created. In numpy, this can be achieved using a combination of transpose and reshape.

Note that in numpy, care is taken to make transpose return a view on the data whenever possible. In theano this is probably the case, too, but may depend on how the code is optimized.