Skip to content

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

np.random.seed(123)
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)
[[[[2. 2. 6. 1. 3.]
   [6. 1. 0. 1. 0.]
   [0. 3. 4. 0. 0.]
   [4. 1. 7. 3. 2.]
   [4. 7. 2. 4. 8.]]]]
slc = Slice()[:, :, 1:-1, 1:-1]
print(slc(data))
[[[[1. 0. 1.]
   [3. 4. 0.]
   [1. 7. 3.]]]]