# of nodes in hidden layer

How do we decide how many nodes each of the hidden layer should have?
For example in the last exercise we had this:
layers_dims = [12288, 20, 7, 5, 1] # 4-layer model
Why do we have 20,7, 5 nodes in hidden layers?

Experimentation.

Generally, you want a model that gives good enough results, but also doesn’t take too long to train.

Is there a known pattern that nodes at hidden layer L1 should be greater than hidden layer L2 where L1 is first hidden layer feeding into next hidden layer L2? Or is that also dependent of the problem domain?

The sizes of the hidden layers tend to either remain the same (which can make the code easier to implement), or to decrease (reducing the amount of computation) closer to the output layer.