RandomArrayLayer[dist]
represents a net layer that has no input and produces a random array from the univariate distribution dist.
RandomArrayLayer[dfunc]
uses the univariate distribution dfunc[input] for each input value.
RandomArrayLayer
RandomArrayLayer[dist]
represents a net layer that has no input and produces a random array from the univariate distribution dist.
RandomArrayLayer[dfunc]
uses the univariate distribution dfunc[input] for each input value.
Details and Options
- In RandomArrayLayer[dist], the distribution dist can be any one of the following univariate distributions: NormalDistribution, UniformDistribution, GammaDistribution, ExponentialDistribution, PoissonDistribution, MaxwellDistribution, RayleighDistribution, ChiDistribution, HalfNormalDistribution, WeibullDistribution, NakagamiDistribution, ChiSquareDistribution, ErlangDistribution, LogGammaDistribution, ExpGammaDistribution, InverseGammaDistribution, BernoulliDistribution, BinomialDistribution, NegativeBinomialDistribution or DiscreteUniformDistribution.
- RandomArrayLayer[dist][] generates a random array or scalar, depending on the output shape.
- In RandomArrayLayer[dfunc], the number of input ports in the layer is the number of arguments of the function dfunc.
- In RandomArrayLayer[dfunc], the output will be an array consisting of independent draws of the corresponding distributions, whose parameters are taken elementwise from the input arrays.
- RandomArrayLayer[Function[… #Name1 … #Name2 …], …] exposes input ports named "Name1", "Name2", etc.
- Besides input ports, RandomArrayLayer exposes the following ports for use in NetGraph etc.:
-
"Output" an array - RandomArrayLayer[…,"port"shape] can be used as in NetGraph to specify the shape, encoder or decoder of a given port.
- Options[RandomArrayLayer] gives the list of default options to construct the layer. Options[RandomArrayLayer[…]] gives the list of default options to evaluate the layer on some data.
- Information[RandomArrayLayer[…]] gives a report about the layer.
- Information[RandomArrayLayer[…],prop] gives the value of the property prop of RandomArrayLayer[…]. Possible properties are the same as for NetGraph.
Examples
open all close allBasic Examples (2)
Create a layer that draws 3 samples from a unit normal distribution:
ra = RandomArrayLayer[NormalDistribution[], "Output" -> 3]ra[]Create a layer that draws samples from independent normal distributions whose means are determined by the input:
ra = RandomArrayLayer[NormalDistribution[#, 1]&]Sample a random vector with given values for the mean:
ra[{-10, 0, 10}]Scope (3)
Arguments (2)
Create a layer that draws real numbers from independent normal distributions whose means and standard deviations are determined by the inputs:
ra = RandomArrayLayer[NormalDistribution[#1, #2]&]Sample a random vector with given values for the mean and the standard deviation of the Gaussian distribution:
ra[{{-10, 0, 10}, {0.01, 1, 100}}]Create the same layer with custom input port names:
ra = RandomArrayLayer[NormalDistribution[#μ, #σ]&]Sample random numbers with this layer:
ra[<|"μ" -> {-10, 0, 10}, "σ" -> {0.01, 1, 100}|>]Create a layer that draws integers in a given range:
ra = RandomArrayLayer[DiscreteUniformDistribution[{1, #Max}]&]Sample random integers with given upper bounds:
ra[{10, 100, 1000}]Ports (1)
Create a layer that draws a sequence of bounded integers with the same length as a given input:
ra = RandomArrayLayer[DiscreteUniformDistribution[{1, 3}]&, "Inputs" -> {"Varying"}]Sample a sequence of integers with different given lengths:
ra[Range /@ {1, 3, 6, 12}]Applications (2)
Build a network that sums an array and a random vector drawn from a Gaussian distribution:
noiser = NetGraph[{RandomArrayLayer[NormalDistribution[0, 0.2]], Plus}, {{1, NetPort["Input"]} -> 2}]noiser[(| | | |
| -- | -- | -- |
| 1 | 2 | 3 |
| -1 | -2 | -3 |)]//MatrixFormApply the net to lists of different lengths:
noiser[{{1, 2}, {1, 0, -1, -2, -3}}]Derive a network that adds noise to images, by attaching an input NetEncoder and an output NetDecoder:
imagenoiser = NetReplacePart[noiser, {"Input" -> NetEncoder["Image"], "Output" -> NetDecoder["Image"]}]imagenoiser[[image]]Build a network that masks a vector of integers with a particular integer value, with a probability to switch a value of 0.3:
integerpadder = NetGraph[{RandomArrayLayer[BernoulliDistribution[0.3]], ThreadingLayer[If[#1 > 0, 4, #2]&]}, {{1, NetPort["Input"]} -> 2}, "Input" -> {Automatic, Restricted["Integer", 3]}]Apply the random mask to some inputs:
integerpadder[{{1, 2, 3, 1, 2, 3}, {3, 2, 1, 3, 2, 1, 3, 2, 1, 3, 2, 1}}]Related Guides
History
Text
Wolfram Research (2020), RandomArrayLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomArrayLayer.html.
CMS
Wolfram Language. 2020. "RandomArrayLayer." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/RandomArrayLayer.html.
APA
Wolfram Language. (2020). RandomArrayLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomArrayLayer.html
BibTeX
@misc{reference.wolfram_2026_randomarraylayer, author="Wolfram Research", title="{RandomArrayLayer}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/RandomArrayLayer.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_randomarraylayer, organization={Wolfram Research}, title={RandomArrayLayer}, year={2020}, url={https://reference.wolfram.com/language/ref/RandomArrayLayer.html}, note=[Accessed: 13-June-2026]}