chainer.functions.swapaxes

chainer.functions.swapaxes(x, axis1, axis2)[source]

Swap two axes of a variable.

Parameters:
  • x (Variable or numpy.ndarray or cupy.ndarray) – Input variable. A \((s_1, s_2, ..., s_N)\) -shaped float array.
  • axis1 (int) – The first axis to swap.
  • axis2 (int) – The second axis to swap.
Returns:

Variable whose axes are swapped.

Return type:

Variable

Example

>>> x = np.array([[[0, 1, 2], [3, 4, 5]]], 'f')
>>> x.shape
(1, 2, 3)
>>> y = F.swapaxes(x, axis1=0, axis2=1)
>>> y.shape
(2, 1, 3)
>>> y.data
array([[[ 0.,  1.,  2.]],

       [[ 3.,  4.,  5.]]], dtype=float32)