PartLayer

PartLayer[i]

represents a net layer that gives the i^(th) part of the input.

PartLayer[m;;n]

gives parts m through n.

PartLayer[{spec1,spec2,}]

takes part speci at level i in the input.

Details and Options

  • PartLayer[][input] explicitly computes the output from applying the layer to input.
  • PartLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • PartLayer exposes the following ports for use in NetGraph etc.:
  • "Input"an array
    "Output"an array
  • PartLayer is typically used inside NetChain, NetGraph, etc.
  • PartLayer normally infers the dimensions of its input from its context in NetChain etc. To specify the dimensions explicitly as {n1,n2,}, use PartLayer["Input"->{n1,n2,}].
  • PartLayer[m;;n] gives an output that is of the same rank as the input, whereas PartLayer[i] gives an output that is one rank smaller.
  • Information[PartLayer[]] gives a report about the layer.
  • Information[PartLayer[],prop] gives the value of the property prop of PartLayer[]. Possible properties are the same as for NetGraph.

Examples

open allclose all

Basic Examples  (2)

Create a PartLayer that takes the second part of an array:

Create a PartLayer that takes the second part of an array:

Apply the layer to a vector:

Scope  (5)

Create a PartLayer that takes the first two elements:

Apply the layer to a matrix:

Create a PartLayer that takes the next-to-last element in an array:

Apply the layer to a vector:

Create a PartLayer that takes all elements after the second one:

Apply the layer to a vector:

This is equivalent to using All:

Create a PartLayer whose inputs are vectors of length three:

The layer threads across a batch of examples:

Create a PartLayer that takes the first column of its input, which is a matrix:

Apply the layer to a matrix:

Possible Issues  (1)

Using Part with a Span where the second index is smaller than the first is valid syntax, producing an empty list:

This is invalid syntax for PartLayer, as empty arrays are not allowed in nets:

Introduced in 2017
 (11.1)
 |
Updated in 2018
 (11.3)