#371 · Deep Learning · Easy
⊣ Solve on deep-ml.comGiven a neural network architecture specified as a list of layer dimensions, calculate the total number of trainable parameters (weights and biases) in the network.
def count_parameters(layer_dims: list[int], use_bias: bool = True) -> int:
total = 0
for i in range(len(layer_dims) - 1):
fan_in = layer_dims[i]
fan_out = layer_dims[i + 1]
total += fan_in * fan_out
if use_bias:
total += fan_out
return totalfan_in * fan_out parameters.fan_out parameters.