ExtractLayer
✖
ExtractLayer
represents a net layer that takes an array and a position specification as inputs and extracts the specified parts from the array.
Details and Options


- ExtractLayer exposes the following ports for use in NetGraph etc.:
-
"Input" input array "Position" integer array of part specifications "Output" output array - ExtractLayer is typically used inside NetChain, NetGraph, etc.
- ExtractLayer normally infers the dimensions of its input from its context in NetChain etc. To specify the dimensions explicitly as {n1,n2,…} and {m1,m2,…}, use ExtractLayer["Input"->{n1,n2,…},"Position"->{m1,m2,…}].
- ExtractLayer["Port"shape] allows the shape of the "Input" or "Position" port to be specified. Possible forms of shape are:
-
n a vector of length n {n1,n2,…} an array of dimensions n1×n2×… {"Varying",n2,n3,…} an array whose first dimension is variable and whose remaining dimensions are n2×n3×… NetEncoder[…] an encoder - The shape of the "Position" port can also be set to "Integer" to specify a single integer.
- The input to the port "Position" is an arbitrary array of part specifications. Given an input of dimensions {n1,n2,…,nd } and a position specification of dimensions {m1,m2,…,mp,s}, the output will have dimensions {m1,m2,…,mp,ns+1,…,nd}.
- The last dimension of the position specification s is used to specify elements of the input, and so it cannot be greater than the input rank d. In the case of s=d, the output dimensions will just be {m1,m2,…,mp}.
- ExtractLayer[…][<"Input"input,"Position"position >] explicitly computes the output from applying the layer to input and position.
- ExtractLayer[…][<"Input"{input1,input2,…},"Input"{pos1,pos2,…} > explicitly computes output for each of the inputi and the posi.
- Negative integers in the position specification are counted from the last element progressing backward.
- When given a NumericArray as input, the output will be a NumericArray.
- Options[ExtractLayer] gives the list of default options to construct the layer. Options[ExtractLayer[…]] gives the list of default options to evaluate the layer on some data.
- Information[ExtractLayer[…]] gives a report about the layer.
- Information[ExtractLayer[…],prop] gives the value of the property prop of ExtractLayer[…]. Possible properties are the same as for NetGraph.
Examples
open allclose allBasic Examples (1)Summary of the most common use cases
Create an ExtractLayer:

https://wolfram.com/xid/0mk946n73e6q-bue9j6

Apply the layer to a vector and a part specification:

https://wolfram.com/xid/0mk946n73e6q-dn4mx9

Scope (2)Survey of the scope of standard use cases
Arguments (1)
Create an ExtractLayer:

https://wolfram.com/xid/0mk946n73e6q-8hhuo1


https://wolfram.com/xid/0mk946n73e6q-mxmszv


https://wolfram.com/xid/0mk946n73e6q-nmgand

Ports (1)
Create an ExtractLayer and specify the shape of its "Input" and "Position" ports:

https://wolfram.com/xid/0mk946n73e6q-td64i9

Apply the layer to an input-position pair:

https://wolfram.com/xid/0mk946n73e6q-wqvf4b

Apply the layer to a batch of input-position pairs:

https://wolfram.com/xid/0mk946n73e6q-oaiwaz

Properties & Relations (2)Properties of the function, and connections to other functions
ExtractLayer performs the same computation as Extract:

https://wolfram.com/xid/0mk946n73e6q-jdfgmt

https://wolfram.com/xid/0mk946n73e6q-ssqozk

https://wolfram.com/xid/0mk946n73e6q-6zir0r


https://wolfram.com/xid/0mk946n73e6q-ldtqg2

ExtractLayer selects parts of an array based on the current specification, while PartLayer has a fixed-part specification:

https://wolfram.com/xid/0mk946n73e6q-z1xb8e

https://wolfram.com/xid/0mk946n73e6q-7npalv

https://wolfram.com/xid/0mk946n73e6q-tkyfzp


https://wolfram.com/xid/0mk946n73e6q-omsf12


https://wolfram.com/xid/0mk946n73e6q-ga8k4q


https://wolfram.com/xid/0mk946n73e6q-1jarjw

PartLayer only supports a single-part specification and not an arbitrary array of those, but accepts Span to extract chunks of the input:

https://wolfram.com/xid/0mk946n73e6q-bgte5h


https://wolfram.com/xid/0mk946n73e6q-vc505d

Possible Issues (3)Common pitfalls and unexpected behavior
The last dimension of the position specification selects the desired parts of the input; hence its size must not exceed the input rank:

https://wolfram.com/xid/0mk946n73e6q-iw2dyz


If the "Position" specification has a rank of 1, its size cannot be variable:

https://wolfram.com/xid/0mk946n73e6q-kztzt3


An unspecified ExtractLayer will always assume it is being evaluated on a single example and not on a batch. In the following, the arrays data and pos will be interpreted as a single 2×3 input array and a 2×1 part specification, respectively:

https://wolfram.com/xid/0mk946n73e6q-y9cqwb

https://wolfram.com/xid/0mk946n73e6q-v9xsdh

https://wolfram.com/xid/0mk946n73e6q-5bb0ja

In order to have them interpreted as a batch of two lists of length 3 and 1, respectively, explicit shapes must be specified prior to evaluation:

https://wolfram.com/xid/0mk946n73e6q-tp4j6u

Wolfram Research (2019), ExtractLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ExtractLayer.html.
Text
Wolfram Research (2019), ExtractLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ExtractLayer.html.
Wolfram Research (2019), ExtractLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ExtractLayer.html.
CMS
Wolfram Language. 2019. "ExtractLayer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ExtractLayer.html.
Wolfram Language. 2019. "ExtractLayer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ExtractLayer.html.
APA
Wolfram Language. (2019). ExtractLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExtractLayer.html
Wolfram Language. (2019). ExtractLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ExtractLayer.html
BibTeX
@misc{reference.wolfram_2025_extractlayer, author="Wolfram Research", title="{ExtractLayer}", year="2019", howpublished="\url{https://reference.wolfram.com/language/ref/ExtractLayer.html}", note=[Accessed: 29-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_extractlayer, organization={Wolfram Research}, title={ExtractLayer}, year={2019}, url={https://reference.wolfram.com/language/ref/ExtractLayer.html}, note=[Accessed: 29-March-2025
]}