#164Dense layer — count the parametersEasyNeural Networks
Dense layer — count the parameters
Background
A fully connected (dense) layer from inputs to outputs has a weight matrix plus one bias per output neuron:
Every input connects to every output ( weights), and each output neuron adds a bias ( more).
Problem statement
Implement dense_params(n_in, n_out) returning the number of trainable parameters in one dense layer.
Input
n_in—int, number of input neurons.n_out—int, number of output neurons.
Output
Returns an int: .
Examples
Example 1
Input: n_in = 5, n_out = 3
Output: 18
Explanation: .
Example 2 — the lesson's first layer
Input: n_in = 3, n_out = 4
Output: 16
Explanation: .
Constraints
- Count weights and biases: .
- Return a plain
int.
Notes
- A handy refactor is — the "+1" is the bias folded in as an extra input that is always 1.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Example: 5 inputs to 3 outputs
- •Reference: lesson layer 3 to 4
- •Sample: lesson layer 4 to 2