NetArray[]
represents an array in a net.
NetArray["name"]
uses "name" as an identifier to share the array in more than one layer.
NetArray[array]
uses array as a set of initial values for the array.
NetArray[propvalue]
specifies the property prop for the array.
NetArray["Name"name,"Array"array,…]
specifies several properties for the array.
NetArray
NetArray[]
represents an array in a net.
NetArray["name"]
uses "name" as an identifier to share the array in more than one layer.
NetArray[array]
uses array as a set of initial values for the array.
NetArray[propvalue]
specifies the property prop for the array.
NetArray["Name"name,"Array"array,…]
specifies several properties for the array.
Details
- NetArray is typically used to share arrays in NetChain/NetGraph or to define learnable parameters in FunctionLayer[…].
- All net arrays sharing the same name in a net are treated as the same underlying array by NetInitialize, NetTrain, etc.
- The properties that can be specified are:
-
"Array" initial values or inialization method for the array "Dimensions" dimensions of the array "Name" name of the array, so that it can be shared - NetArray[] automatically gives a name (UUID) to the array and is equivalent to NetArray[Automatic].
- NetInsertSharedArrays[layer] will return a new layer in which all its arrays have been replaced with named net arrays.
Examples
open all close allBasic Examples (1)
Create a net that contains a shared array, used in two layers:
net = NetInitialize@NetChain[{
LinearLayer[2, "Weights" -> NetArray["W"]],
Ramp,
LinearLayer[2, "Weights" -> NetArray["W"]]
}]The weights from the two linear layers are the same (and will remain the same when training with NetTrain):
NetExtract[net, {1, "Weights"}]NetExtract[net, {3, "Weights"}]Scope (3)
Use an uninitialized learnable NetArray in FunctionLayer:
FunctionLayer[Function[# + NetArray[]], "Input" -> 2]Use an uninitialized learnable NetArray in FunctionLayer specifying its dimensions:
plusArray = FunctionLayer[Function[# + NetArray[<|"Dimensions" -> 2|>]], "Input" -> 2]Having specified the dimensions, the above net can be initialized and evaluated on an input:
inizialized = NetInitialize[plusArray]inizialized[{3, 4}]The original NetArray corresponds to a NetArrayLayer in the equivalent NetGraph:
NetGraph[inizialized]The array was initialized to zeros:
Normal@NetExtract[inizialized, {"Net", 1, "Array"}]Use an initialized learnable NetArray in FunctionLayer:
plusArray = FunctionLayer[Function[# + NetArray[{1, 2}]], "Input" -> 2]Evaluate the layer on an input:
plusArray[{3, 4}]Normal@NetExtract[plusArray, {"Net", "1", "Array"}]Properties & Relations (2)
NetExtract can extract all shared arrays in a net:
net = NetInitialize@NetChain[{LinearLayer[2, "Weights" -> NetArray["W"]], Ramp, LinearLayer[2, "Weights" -> NetArray["W"]]}]NetExtract[net, NetArray[All]]When obtaining all arrays in a net with Information, shared arrays will appear with keys of the form NetArray["Name"]:
net = NetInitialize@NetChain[{LinearLayer[2, "Weights" -> NetArray["W"]], Ramp, LinearLayer[2, "Weights" -> NetArray["W"]]}]Information[net, "Arrays"]Tech Notes
Related Guides
History
Text
Wolfram Research (2020), NetArray, Wolfram Language function, https://reference.wolfram.com/language/ref/NetArray.html.
CMS
Wolfram Language. 2020. "NetArray." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/NetArray.html.
APA
Wolfram Language. (2020). NetArray. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NetArray.html
BibTeX
@misc{reference.wolfram_2026_netarray, author="Wolfram Research", title="{NetArray}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/NetArray.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_netarray, organization={Wolfram Research}, title={NetArray}, year={2020}, url={https://reference.wolfram.com/language/ref/NetArray.html}, note=[Accessed: 13-June-2026]}