RandomArrayLayer
✖
RandomArrayLayer
represents a net layer that has no input and produces a random array from the univariate distribution dist.
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 allclose allBasic Examples (2)Summary of the most common use cases
Create a layer that draws 3 samples from a unit normal distribution:

https://wolfram.com/xid/0e5bx4bznvwp66-jolvlg


https://wolfram.com/xid/0e5bx4bznvwp66-ghoqkp

Create a layer that draws samples from independent normal distributions whose means are determined by the input:

https://wolfram.com/xid/0e5bx4bznvwp66-kumhqs

Sample a random vector with given values for the mean:

https://wolfram.com/xid/0e5bx4bznvwp66-4lw9h0

Scope (3)Survey of the scope of standard use cases
Arguments (2)
Create a layer that draws real numbers from independent normal distributions whose means and standard deviations are determined by the inputs:

https://wolfram.com/xid/0e5bx4bznvwp66-fjvemz

Sample a random vector with given values for the mean and the standard deviation of the Gaussian distribution:

https://wolfram.com/xid/0e5bx4bznvwp66-2inh7k

Create the same layer with custom input port names:

https://wolfram.com/xid/0e5bx4bznvwp66-0p42d7

Sample random numbers with this layer:

https://wolfram.com/xid/0e5bx4bznvwp66-ws4qtz

Create a layer that draws integers in a given range:

https://wolfram.com/xid/0e5bx4bznvwp66-g0o64v

Sample random integers with given upper bounds:

https://wolfram.com/xid/0e5bx4bznvwp66-pe3xa5

Ports (1)
Applications (2)Sample problems that can be solved with this function
Build a network that sums an array and a random vector drawn from a Gaussian distribution:

https://wolfram.com/xid/0e5bx4bznvwp66-2pmwbz


https://wolfram.com/xid/0e5bx4bznvwp66-g4x2dw

Apply the net to lists of different lengths:

https://wolfram.com/xid/0e5bx4bznvwp66-iulxz8

Derive a network that adds noise to images, by attaching an input NetEncoder and an output NetDecoder:

https://wolfram.com/xid/0e5bx4bznvwp66-eijyjq


https://wolfram.com/xid/0e5bx4bznvwp66-kfrgss

Build a network that masks a vector of integers with a particular integer value, with a probability to switch a value of 0.3:

https://wolfram.com/xid/0e5bx4bznvwp66-z79qlt

Apply the random mask to some inputs:

https://wolfram.com/xid/0e5bx4bznvwp66-8afgrz

Wolfram Research (2020), RandomArrayLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomArrayLayer.html.
Text
Wolfram Research (2020), RandomArrayLayer, Wolfram Language function, https://reference.wolfram.com/language/ref/RandomArrayLayer.html.
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.
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
Wolfram Language. (2020). RandomArrayLayer. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/RandomArrayLayer.html
BibTeX
@misc{reference.wolfram_2025_randomarraylayer, author="Wolfram Research", title="{RandomArrayLayer}", year="2020", howpublished="\url{https://reference.wolfram.com/language/ref/RandomArrayLayer.html}", note=[Accessed: 26-March-2025
]}
BibLaTeX
@online{reference.wolfram_2025_randomarraylayer, organization={Wolfram Research}, title={RandomArrayLayer}, year={2020}, url={https://reference.wolfram.com/language/ref/RandomArrayLayer.html}, note=[Accessed: 26-March-2025
]}