Reorder the dimensions of this variable, optionally inserting broadcasted dimensions.
Returns a view of this variable with permuted dimensions. Typically the pattern will include the integers
0, 1, ... ndim-1, and any number of
'x'characters in dimensions where this variable should be broadcasted.
A few examples of patterns and their effect:
('x',): make a 0d (scalar) into a 1d vector
(0, 1): identity for 2d vectors
(1, 0): inverts the first and second dimensions
('x', 0): make a row out of a 1d vector (N to 1xN)
(0, 'x'): make a column out of a 1d vector (N to Nx1)
(2, 0, 1): AxBxC to CxAxB
(0, 'x', 1): AxB to Ax1xB
(1, 'x', 0): AxB to Bx1xA
(1,): This removes the dimension at index 0. It must be a broadcastable dimension.
pattern – List/tuple of int mixed with ‘x’ for broadcastable dimensions.
For example, to create a 3D view of a [2D] matrix, call
dimshuffle([0,'x',1]). This will create a 3D view such that the middle dimension is an implicit broadcasted dimension. To do the same thing on the transpose of that matrix, call
dimshuffle([1, 'x', 0]).
This function supports the pattern passed as a tuple, or as a variable-length argument (e.g.
a.dimshuffle(pattern)is equivalent to
patternis a list/tuple of ints mixed with ‘x’ characters).