Skip to content

MoveAxis

Description

Info

Parent class: Module

Derived classes: -

This module moves the tensor axis. An analog of the moveaxis function in numpy.

Initializing

def __init__(self, src, dst, name=None):

Parameters

Parameter Allowed types Description Default
src int Starting axis position -
dst int Target axis position -
name str Layer name None

Explanations

-

Examples

Necessary imports.

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

Info

gpuarray is required to properly place the tensor in the GPU

batchsize, maps, h, w = 1, 1, 3, 3
data = gpuarray.to_gpu(np.arange(batchsize * maps * h * w).reshape((batchsize, maps, h, w)).astype(np.float32))
print(data)
[[[[0. 1. 2.]
   [3. 4. 5.]
   [6. 7. 8.]]]]

Let us set the parameters in such a way as to swap the axes of height and width (which will be equivalent to transposing the map):

src, dst = 2, 3
moveaxis = MoveAxis(src, dst)
print(moveaxis(data))
[[[[0. 3. 6.]
   [1. 4. 7.]
   [2. 5. 8.]]]]