Contenido principal

sliceLayer

R2026b

Slice layer

Since R2026b

    Description

    A slice layer selects elements from a specified dimension of the input data.

    Creation

    Description

    layer = sliceLayer(dim,indices) creates a slice layer that selects the elements specified by indices from the dimension dim of the layer input.

    example

    layer = sliceLayer(dim,indices,Name=name) also sets the Name property. For example, Name="slice" specifies the layer name.

    Input Arguments

    expand all

    Dimension to slice, specified as a positive integer.

    This argument sets the Dimension property.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Slicing indices, specified as one of these:

    • Vector of positive integers — The layer outputs a single array that corresponds to the specified indices. For example, for the vector [1 3], the layer has one output that corresponds to indices 1 and 3 of the input.

    • Cell array of vectors of positive integers — The layer outputs multiple arrays that correspond to the index vectors in the cell array. For example, for the cell array {[1 3],[2 4]}, the layer has two outputs, where the first output corresponds to indices 1 and 3 of the input, and the second output corresponds to indices 2 and 4 of the input.

    This argument sets the Indices property.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | cell

    Layer name, specified as a character vector or a string scalar. For Layer array input, the trainnet and dlnetwork functions automatically assign names to unnamed layers.

    This argument sets the Name property.

    Data Types: char | string

    Properties

    expand all

    Slice

    Dimension to slice, stored as a positive integer.

    This property is read-only after object creation. To set this property, use the corresponding positional input argument when you create the SliceLayer object.

    Data Types: double

    Slicing indices, specified as one of these:

    • Vector of positive integers — The layer outputs a single array that corresponds to the specified indices. For example, for the vector [1 3], the layer has one output that corresponds to indices 1 and 3 of the input.

    • Cell array of vectors of positive integers — The layer outputs multiple arrays that correspond to the index vectors in the cell array. For example, for the cell array {[1 3],[2 4]}, the layer has two outputs, where the first output corresponds to indices 1 and 3 of the input, and the second output corresponds to indices 2 and 4 of the input.

    When Indices is a numeric vector, the layer has one output with the name 'out'. When Indices is a cell array, the layer has outputs with the names 'out1', 'out2', ..., 'outN', where N is the number of elements of Indices. For example, the output 'outK' corresponds to the indices Indices(K).

    This property is read-only after object creation. To set this property, use the corresponding positional input argument when you create the SliceLayer object.

    Data Types: double | cell

    Layer

    Layer name, specified as a character vector. For Layer array input, the trainnet and dlnetwork functions automatically assign names to unnamed layers.

    Data Types: char

    This property is read-only.

    Number of inputs to the layer, represented as 1. This layer has a single input only.

    Data Types: double

    This property is read-only.

    Input name, represented as {'in'}. This layer has a single input only.

    This property is read-only.

    Number of outputs from the layer, represented as a positive integer.

    When Indices is a numeric vector, the layer has one output with the name 'out'. When Indices is a cell array, the layer has outputs with the names 'out1', 'out2', ..., 'outN', where N is the number of elements of Indices. For example, the output 'outK' corresponds to the indices Indices(K).

    Data Types: double

    This property is read-only.

    Output names from the layer, represented as a cell array of character vectors.

    When Indices is a numeric vector, the layer has one output with the name 'out'. When Indices is a cell array, the layer has outputs with the names 'out1', 'out2', ..., 'outN', where N is the number of elements of Indices. For example, the output 'outK' corresponds to the indices Indices(K).

    Data Types: cell

    Examples

    collapse all

    Create a slice layer that selects the first and third elements from the first dimension of the layer input.

    layer = sliceLayer(1,[1 3])
    layer = 
      SliceLayer with properties:
    
             Name: ''
        Dimension: 1
          Indices: [1 3]
    
       Hyperparameters
        No properties.
    
    

    Algorithms

    expand all

    Extended Capabilities

    expand all

    C/C++ Code Generation
    Generate C and C++ code using MATLAB® Coder™.

    GPU Code Generation
    Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.

    Version History

    Introduced in R2026b