PartLayer
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[i;;j] and PartLayer[i;;j;;k] give 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 all close allBasic Examples (2)
Scope (6)
Arguments (3)
Create a PartLayer that takes the first two elements:
p = PartLayer[1 ;; 2]p[{{1, 2}, {3, 4}, {5, 6}}]Create a PartLayer that takes the next-to-last element in an array:
p = PartLayer[-2]p[{1, 2, 3, 4, 5, 6}]Create a PartLayer that takes all elements after the second one:
p = PartLayer[2 ;; ]p[{-1, -2, -3, -4, -5}]This is equivalent to using All:
PartLayer[2 ;; All][{-1, -2, -3, -4, -5}]Ports (3)
Create a PartLayer whose inputs are vectors of length three:
p = PartLayer[2, "Input" -> 3]The layer threads across a batch of examples:
p[{{1, 2, 3}, {0.1, 0.2, 0.3}}]Create a PartLayer that takes the first column of its input, which is a matrix:
p = PartLayer[{All, 1}, "Input" -> {2, 3}]p[{{1, 2, 3}, {4, 5, 6}}]Create a PartLayer that takes numbers at an odd place:
p = PartLayer[ ;; ;; 2, "Input" -> {Automatic}]Apply the layer to a list of numbers:
p[Range[10]]Tech Notes
Related Guides
Text
Wolfram Research (2017), PartLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/PartLayer.html (updated 2021).
CMS
Wolfram Language. 2017. "PartLayer." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/PartLayer.html.
APA
Wolfram Language. (2017). PartLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/PartLayer.html
BibTeX
@misc{reference.wolfram_2026_partlayer, author="Wolfram Research", title="{PartLayer}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/PartLayer.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_partlayer, organization={Wolfram Research}, title={PartLayer}, year={2021}, url={https://reference.wolfram.com/language/ref/PartLayer.html}, note=[Accessed: 13-June-2026]}