Surely the instructions for that section must say something about how to handle that. Please have another careful look. I don’t have access to the M4ML courses, but they copied this assignment from DLS C1 W3 and there the instructions quite clearly tell you what to do about n_h. You can’t compute it from the shapes of X and Y.
Dear @Josue as @paulinpaloalto very accurately mentioned, you cannot extract n_h from X and Y, because otherwise how could we have so many neural networks with different architectures and different layer sizes?
In this specific notebook, we are instructed to set n_h equal to 2.
Setting the best number of hidden layers and the best number of nodes in each layer is a tricky task, and they are considered as hyperparameters. You will learn to set these parameters much better as you gain more experience working with NNs.
There’s an important “meta” lesson here: if you think you are “saving time” by not reading the instructions carefully, it almost always ends up not being a net savings of time. You “save” a couple of minutes and then waste a couple of hours trying to figure out what went wrong.