Skip to content

SwapAxes

Description

Info

Parent class: Module

Derived classes: -

This module reverses the tensor values along the axes. An analog of the swapaxes function in numpy.

Initializing

def __init__(self, axis1, axis2, name=None):

Parameters

Parameter Allowed types Description Default
axis1 int First axis index -
axis2 int Second axis index -
name str Layer name None

Explanations

-

Examples

Necessary imports.

import numpy as np
from PuzzleLib.Backend import gpuarray
from PuzzleLib.Modules import SwapAxes

Let us form the data tensor. Please, pay attention to the current format: (batchsize, insize).

shape = (10, 3, 5, 4, 2)
data = gpuarray.to_gpu(np.random.randn(*shape).astype(np.float32))
print(data.shape)
(10, 3, 5, 4, 2)
swap = SwapAxes(axis1=2, axis2=4)
outdata = swap(data)
print(outdata.shape)
(10, 3, 2, 4, 5)
swap = SwapAxes(axis1=0, axis2=2)
outdata = swap(data)
print(outdata.shape)
(5, 3, 10, 4, 2)