chainer.functions.transpose

chainer.functions.transpose(x, axes=None)[source]

Permute the dimensions of an input variable without copy.

Parameters:
  • x (Variable or numpy.ndarray or cupy.ndarray) – Input variable to be transposed. A \((s_1, s_2, ..., s_N)\) -shaped float array.
  • axes (tuple of ints) – By default, reverse the dimensions, otherwise permute the axes according to the values given.
Returns:

Variable whose axes are permuted.

Return type:

Variable

Example

>>> x = np.array([[[0, 1, 2], [3, 4, 5]]], np.float32)
>>> x.shape
(1, 2, 3)
>>> y = F.transpose(x)  # reverse the dimensions
>>> y.shape
(3, 2, 1)
>>> y.data
array([[[0.],
        [3.]],
<BLANKLINE>
       [[1.],
        [4.]],
<BLANKLINE>
       [[2.],
        [5.]]], dtype=float32)
>>> y = F.transpose(x, axes=(1, 0, 2)) # swap 1st and 2nd axis
>>> y.shape
(2, 1, 3)
>>> y.data
array([[[0., 1., 2.]],
<BLANKLINE>
       [[3., 4., 5.]]], dtype=float32)