Slice

Description

Info

Parent class: Module

Derived classes: -

This module implements the operation of slicing the data tensor.

Initializing

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

Parameters

Parameter Allowed types Description Default
slc list List of slice objects None
name str Layer name None

Explanations

slc - it is possible to set a slice for convenience instead of a list of slice objects, just like for numpy arrays (see example).

Examples

Necessary imports.

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

Info

gpuarray is required to properly place the tensor in the GPU

>>> batchsize, maps, h, w = 1, 1, 5, 5
>>> data = gpuarray.to_gpu(np.random.randint(0, 9, (batchsize, maps, h, w)).astype(np.float32))
>>> print(data)
[[[[6. 2. 0. 8. 1.]
   [0. 7. 4. 5. 3.]
   [5. 7. 2. 5. 6.]
   [8. 2. 3. 3. 0.]
   [4. 4. 6. 7. 7.]]]]
>>> slc = Slice()[:, :, 1:-1, 1:-1]
>>> slc(data)
[[[[7. 4. 5.]
   [7. 2. 5.]
   [2. 3. 3.]]]]