Transpose

Description

Info

Parent class: Module

Derived classes: -

This module implements a permutation of the input tensor axes in the desired order. An analog of the transpose function in numpy.

Initializing

def __init__(self, axes=None, name=None):

Parameters

Parameter Allowed types Description Default
axes tuple Tuple with the desired axis layout None
name str Layer name None

Explanations

axes - if None, then the usual transpose operation will be performed, otherwise, the permutation is performed in the specified order.

Examples

Necessary imports.

>>> import numpy as np
>>> from PuzzleLib.Backend import gpuarray
>>> from PuzzleLib.Modules import Transpose

Info

gpuarray is required to properly place the tensor in the GPU

>>> shape = (10, 3, 5, 4, 2)
>>> axes = (2, 4, 1, 3, 0)
>>> data = gpuarray.to_gpu(np.random.randn(*shape).astype(np.float32))

Let us initialize the operation with the default parameters (axes=None):

>>> transpose = Transpose()
>>> outdata = transpose(data)
>>> print(outdata.shape)
(2, 4, 5, 3, 10)

This time let us set the desired axis order:

>>> transpose = Transpose(axes)
>>> outdata = transpose(data)
>>> print(outdata.shape)
(5, 2, 3, 4, 10)