Search notes:

torch.nn.Linear

import torch

lin = torch.nn.Linear(3, 2) # three inputs, two outputs

print(lin.bias  .shape)    # torch.Size([2])     = number of outputs
print(lin.weight.shape)    # torch.Size([2, 3])  = number of outputs x number of inputs


x_0 = 1.0
x_1 = 2.2
x_2 = 0.9
x_tensor = torch.tensor([ x_0, x_1, x_2 ])

print( x_tensor @ lin.weight.t() + lin.bias )     # Explicit matrix operations.
print(lin( x_tensor ))                            # Same thing, but using torch.nn.Linear

Index