represents a trainable, fully connected net layer that computes with output vector of size n.


represents a layer that outputs an array of dimensions n1×n2×.


leaves the dimensions of the output array to be inferred from context.


includes options for initial weights and other parameters.

Details and Options

  • The following optional parameters can be included:
  • "Biases"Automaticinitial vector of biases (b in w.x+b)
    "Weights"Automaticinitial matrix of weights (w in w.x+b)
  • When weights and biases are not explicitly specified or are given as Automatic, they are added automatically when NetInitialize or NetTrain is used.
  • The setting "Biases"->None specifies that no biases should be used.
  • If weights and biases have been added, LinearLayer[][input] explicitly computes the output from applying the layer.
  • LinearLayer[][{input1,input2,}] explicitly computes outputs for each of the inputi.
  • When given a NumericArray as input, the output will be a NumericArray.
  • NetExtract can be used to extract weights and biases from a LinearLayer object.
  • LinearLayer is typically used inside NetChain, NetGraph, etc.
  • LinearLayer exposes the following ports for use in NetGraph etc.:
  • "Input"an array
    "Output"an array of size n1×n2×
  • LinearLayer[{}] specifies that the LinearLayer should produce a single real number.
  • LinearLayer[n,"Input"->m] is the most common usage of LinearLayer and represents a LinearLayer that takes a vector of length m and produces a vector of length n.
  • When it cannot be inferred from previous layers in a larger net, the option "Input"shape can be used to fix the input of LinearLayer. Possible forms for shape include:
  • "Real"a single real number
    ma vector of length m
    {m1,m2,}an array of dimensions m1×m2×
    NetEncoder[]an encoder


open all close all

Basic Examples  (2)

Create a LinearLayer whose output is a length-5 vector:

Click for copyable input

Create a randomly initialized LinearLayer:

Click for copyable input

Apply the layer to an input vector to produce an output vector:

Click for copyable input

Scope  (6)

Options  (2)

Applications  (1)

Properties & Relations  (3)

Possible Issues  (3)

Introduced in 2016