NetMapOperator[net]
represents a net in which net is mapped over a sequence of inputs to give a sequence of outputs.
NetMapOperator
NetMapOperator[net]
represents a net in which net is mapped over a sequence of inputs to give a sequence of outputs.
Details and Options
- NetMapOperator[net] represents a net that takes a sequence of arrays and outputs a sequence of the same length.
- NetMapOperator[net] accepts a single input sequence {x1,x2,…,xn} and computes {net[x1],net[x2],…,net[xn]}.
- In NetMapOperator[net], net should take exactly one input and produce exactly one output.
- NetExtract can be used to extract net from a NetMapOperator[net] object.
- The input and output ports of the net represented by NetMapOperator are:
-
"Input" a sequence of arrays "Output" a sequence of arrays - NetMapOperator[net] can be seen as allowing a form of weight sharing between multiple copies of net, one for each sequence element that is being mapped.
- NetMapOperator[net,"Input"->shape] allows the shape of the input to be specified. Possible forms for shape are:
-
d a vector of size d {d1,d2} a matrix of size d1×d2 {d1,d2,…} an array of shape d1×d2×… {"Varying",d2,d3,…} an array whose first dimension is variable and whose remaining dimensions are d2×d3×… - The following training parameter can be included:
-
LearningRateMultipliers Automatic learning rate multipliers for trainable arrays in the net - NetExtract allows access to the forward and reverse nets via "Net".
- Options[NetMapOperator] gives the list of default options to construct the operator. Options[NetMapOperator[…]] gives the list of default options to evaluate the operator on some data.
- Information[NetMapOperator[…]] gives a report about the operator.
- Information[NetMapOperator[…],prop] gives the value of the property prop of NetMapOperator[…]. Possible properties are the same as for NetGraph.
Examples
open all close allBasic Examples (2)
Create a NetMapOperator that maps a LinearLayer over a sequence:
NetMapOperator[LinearLayer[]]Create a NetMapOperator that maps a SummationLayer over a sequence:
map = NetMapOperator[SummationLayer["Input" -> 2]]Apply the layer to a sequence of vectors:
map[{{1, 2}, {3, 4}, {5, 6}}]The layer threads across a batch of sequences of different lengths:
map[{{{1, 2}, {3, 4}}, {{5, 6}, {7, 8}, {9, 10}}}]Scope (3)
Create a net that maps a LinearLayer over a sequence of vectors that have been one-hot encoded from the characters of a string:
map = NetInitialize @ NetMapOperator[LinearLayer[2], "Input" -> NetEncoder[{"Characters", Automatic, "UnitVector"}]]map["abc"]//MatrixFormmap["abcxyz"]//MatrixFormThe initialized LinearLayer can be obtained using NetExtract:
NetExtract[map, "Net"]Create a net that maps a single pooling layer over a pair of images. First create a pooling layer that operates on images:
pool = PoolingLayer[16, "Input" -> NetEncoder["Image"], "Output" -> NetDecoder["Image"]]pool[[image]]Create a net that maps the pooling layer over sequences of images:
map = NetMapOperator[pool]map[{[image], [image]}]Use NetMapOperator to apply a one-dimensional pooling to each row of an image:
map = NetMapOperator[PoolingLayer[20], "Input" -> NetEncoder["Image"], "Output" -> NetDecoder["Image"]]map[[image]]Applications (1)
Sorting lists of numbers. Generate a test and training set consisting of lists of integers between 1 and 6:
digits = Range[6];
seqs = RandomSample[Flatten[Table[Tuples[digits, n], {n, 3, 6}], 1]];
data = Map[# -> Sort[#]&, seqs];
{testData, trainData} = TakeDrop[data, Ceiling[Length[data] / 10]];Display three random samples drawn from the training set:
RandomSample[trainData, 3]Define a NetGraph with an AttentionLayer:
net = NetGraph[<|
"enc" -> {EmbeddingLayer[12], LongShortTermMemoryLayer[50]}, "dec" -> LongShortTermMemoryLayer[50],
"key" -> NetMapOperator[50],
"value" -> NetMapOperator[50],
"attend" -> AttentionLayer["Dot"],
"cat" -> CatenateLayer[2], "classify" -> {NetMapOperator[LinearLayer[]], SoftmaxLayer[]}
|>, {
"enc" -> "key" -> NetPort["attend", "Key"], "enc" -> "value" -> NetPort["attend", "Value"],
"enc" -> "dec" -> NetPort["attend", "Query"],
"dec" -> "cat", "attend" -> "cat", "cat" -> "classify"}, "Input" -> {"Varying", NetEncoder[{"Class", digits}]}, "Output" -> {"Varying", NetDecoder[{"Class", digits}]}
]trained = NetTrain[net, trainData, MaxTrainingRounds -> 3, ValidationSet -> testData]Use the net to sort a list of integers:
trained[{6, 6, 1, 4, 2}]Properties & Relations (1)
NetMapOperator can be used to implement NetPairEmbeddingOperator. Create an initialized LinearLayer:
linear = NetInitialize@LinearLayer[2, "Input" -> {2}]Create NetPairEmbeddingOperator using the linear layer as its embedding net, and evaluate it on an input:
pairNet = NetPairEmbeddingOperator[linear, "DistanceFunction" -> EuclideanDistance]pairNet[{{1, 2}, {3, 4}}]Define a NetGraph with a NetMapOperator that is equivalent to the previous NetPairEmbeddingOperator, and evaluate it on the same input:
mapNet = NetGraph[{NetMapOperator[linear, "Input" -> {2, 2}], PartLayer[1], PartLayer[2], ThreadingLayer[(#1 - #2) ^ 2&], SummationLayer[]}, {1 -> 2, 1 -> 3, {2, 3} -> 4 -> 5}]mapNet[{{1, 2}, {3, 4}}]Tech Notes
Related Guides
Text
Wolfram Research (2017), NetMapOperator, Wolfram Language function, https://reference.wolfram.com/language/ref/NetMapOperator.html (updated 2020).
CMS
Wolfram Language. 2017. "NetMapOperator." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2020. https://reference.wolfram.com/language/ref/NetMapOperator.html.
APA
Wolfram Language. (2017). NetMapOperator. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetMapOperator.html
BibTeX
@misc{reference.wolfram_2026_netmapoperator, author="Wolfram Research", title="{NetMapOperator}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetMapOperator.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_netmapoperator, organization={Wolfram Research}, title={NetMapOperator}, year={2020}, url={https://reference.wolfram.com/language/ref/NetMapOperator.html}, note=[Accessed: 12-June-2026]}