#174Network — total trainable parametersEasyNeural Networks
Network — total trainable parameters
Background
A feedforward network is a list of layer sizes, e.g. [i, h, o]. The input layer holds no weights — parameters live between consecutive layers. So the total is the sum of each dense layer's parameter count:
where are the layer sizes in order.
Problem statement
Implement network_params(sizes) returning the total number of trainable parameters for a fully connected network described by the list sizes.
Input
sizes— list ofintlayer sizes, input first, output last (length ).
Output
Returns an int: the summed parameters over all consecutive layer pairs.
Examples
Example 1 — the lesson's i=3, h=4, o=2 net
Input: sizes = [3, 4, 2]
Output: 26
Explanation: .
Example 2 — a single layer
Input: sizes = [5, 3]
Output: 18
Explanation: one dense layer, .
Constraints
- The input layer contributes no parameters; only count between consecutive sizes.
- A list with one element (just an input) has
0parameters. - Return a plain
int.
Notes
- This is the network's capacity in raw scalar count. More/wider layers grow it fast — more flexible, but easier to overfit.
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 lesson net
- •reference single layer
- •sample input only