represents a net layer that takes an input of dimensions {d1,d2,…} and replicates it n times to produce an output of dimensions {n,d1,d2,…}.
ReplicateLayer[{n1,n2,…,nm}]
represents a net layer that takes an input of dimensions {d1,d2,…} and replicates it to produce an output of dimensions {n1,n2,…,nm,d1,d2,…}.
ReplicateLayer[dims,m]
replicates so that dims appears at position m in the list of output dimensions.
ReplicateLayer
represents a net layer that takes an input of dimensions {d1,d2,…} and replicates it n times to produce an output of dimensions {n,d1,d2,…}.
ReplicateLayer[{n1,n2,…,nm}]
represents a net layer that takes an input of dimensions {d1,d2,…} and replicates it to produce an output of dimensions {n1,n2,…,nm,d1,d2,…}.
ReplicateLayer[dims,m]
replicates so that dims appears at position m in the list of output dimensions.
Details and Options
- ReplicateLayer[n] is equivalent to ReplicateLayer[n,1].
- For ReplicateLayer[n], the rank of the output array is one larger than the rank of the input array.
- For ReplicateLayer[{n1,…,nm}], the rank of the output array is m larger than the rank of the input array.
- Any of the n or ni can have the value Automatic, leaving the exact output dimension to be inferred from its context in NetChain etc.
- ReplicateLayer[…][input] explicitly computes the output from applying the layer to input.
- ReplicateLayer[…][{input1,input2,…}] explicitly computes outputs for each of the inputi.
- When given a NumericArray as input, the output will be a NumericArray.
- ReplicateLayer exposes the following ports for use in NetGraph etc.:
-
"Input" an array of arbitrary rank "Output" an array of greater rank than the input - ReplicateLayer is typically used inside NetChain, NetGraph, etc.
- ReplicateLayer normally infers the dimensions of its input from its context in NetChain etc. To specify the dimensions explicitly as {n1,n2,…}, use ReplicateLayer["Input"->{n1,n2,…}].
- Options[ReplicateLayer] gives the list of default options to construct the layer. Options[ReplicateLayer[…]] gives the list of default options to evaluate the layer on some data.
- Information[ReplicateLayer[…]] gives a report about the layer.
- Information[ReplicateLayer[…],prop] gives the value of the property prop of ReplicateLayer[…]. Possible properties are the same as for NetGraph.
Examples
open all close allBasic Examples (2)
Create a ReplicateLayer that replicates its input 4 times:
ReplicateLayer[4]Create a ReplicateLayer that replicates its input 3 times:
repl = ReplicateLayer[3]repl[{1, 2}]Scope (6)
Arguments (2)
Create a ReplicateLayer that replicates its input 3×4 times:
repl = ReplicateLayer[{3, 4}]repl[{1, 2}]//MatrixFormCreate a ReplicateLayer that replicates the elements of a vector into rows of length 3:
repl = ReplicateLayer[3, 2]repl[{1, 2}]//MatrixFormThe elements can be replicated into columns instead:
repl2 = ReplicateLayer[3, 1]repl2[{1, 2}]//MatrixFormPorts (4)
Create a ReplicateLayer that takes an input of specific size:
repl = ReplicateLayer[3, "Input" -> {2, 2}]repl[{{1, 2}, {3, 4}}]//MatrixFormCreate a NetGraph containing a ReplicateLayer that automatically broadcasts a vector to a matrix of given size:
graph = NetGraph[{AggregationLayer[Mean], ReplicateLayer[Automatic, 2], ThreadingLayer[Plus]}, {1 -> 2 -> 3, NetPort["Input"] -> 3} ]This NetGraph is now valid for multiple input dimensions:
NetReplacePart[graph, "Input" -> {3, 2}]NetReplacePart[graph, "Input" -> {100, 23}]Create a ReplicateLayer that replicates a single number to form a vector:
repl = ReplicateLayer[3, "Input" -> "Real"]repl[2.9]The layer threads across a batch of inputs:
repl[{2.9, 3.5}]Create a NetChain that makes four copies of an image by replicating and then flattening both spatial dimensions in turn:
repl = NetChain[{TransposeLayer[1 -> 3], ReplicateLayer[2], FlattenLayer[1], TransposeLayer[2 -> 1], ReplicateLayer[2], FlattenLayer[1], TransposeLayer[{3 -> 1, 2 -> 3}]}, "Input" -> NetEncoder["Image"], "Output" -> NetDecoder["Image"]]repl[[image]]Possible Issues (2)
ReplicateLayer cannot accept non-numeric inputs:
repl = ReplicateLayer[2, "Input" -> 2];
repl[{1, 2}]repl[{1, "x"}]ReplicateLayer[dims,pos] will fail when pos is more than one greater than the rank of the input:
repl = ReplicateLayer[{3}, 5, "Input" -> {3, 2, 4}]Tech Notes
Related Guides
Text
Wolfram Research (2017), ReplicateLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/ReplicateLayer.html (updated 2017).
CMS
Wolfram Language. 2017. "ReplicateLayer." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2017. https://reference.wolfram.com/language/ref/ReplicateLayer.html.
APA
Wolfram Language. (2017). ReplicateLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ReplicateLayer.html
BibTeX
@misc{reference.wolfram_2026_replicatelayer, author="Wolfram Research", title="{ReplicateLayer}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/ReplicateLayer.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_replicatelayer, organization={Wolfram Research}, title={ReplicateLayer}, year={2017}, url={https://reference.wolfram.com/language/ref/ReplicateLayer.html}, note=[Accessed: 12-June-2026]}