pytorch dense layer code example

Example 1: dense layer keras

>>> # Create a `Sequential` model and add a Dense layer as the first layer.  
>>> model = tf.keras.models.Sequential()
>>> model.add(tf.keras.Input(shape=(16,)))
>>> model.add(tf.keras.layers.Dense(32, activation='relu'))
>>> # Now the model will take as input arrays of shape (None, 16)  
>>> # and output arrays of shape (None, 32).  
>>> # Note that after the first layer, you don't need to specify  
>>> # the size of the input anymore:  
>>> model.add(tf.keras.layers.Dense(32))
>>> model.output_shape
(None, 32)

Example 2: torch.nn.Linear(in_features, out_features, bias=True) discription

import torch
import torch.nn as nn

x = torch.tensor([[1.0, -1.0],
                  [0.0,  1.0],
                  [0.0,  0.0]])

in_features = x.shape[1]  # = 2
out_features = 2

m = nn.Linear(in_features, out_features)
%%%%
results would be 
>>> m.weight
tensor([[-0.4500,  0.5856],
        [-0.1807, -0.4963]])

>>> m.bias
tensor([ 0.2223, -0.6114])
%%%%