Skip to content

Instantly share code, notes, and snippets.

@Tooluloope
Created March 13, 2019 06:59
Show Gist options
  • Save Tooluloope/419870db5598d4c9977b546a3587d858 to your computer and use it in GitHub Desktop.
Save Tooluloope/419870db5598d4c9977b546a3587d858 to your computer and use it in GitHub Desktop.
def initialize_parameters(layer_dims):
""""
INPUTS:
layers_dim: represents the dimension of each hidden layer in the neural network, the index(i) represents the
layer while layers_dim[i] represents the number of nodes in that layer
RETURN:
this should return intialized paramenters from W1, b1 to Wl-1, bl-1 assuming l = length of layers_dim
where Wi is of shape (L[i], L[i-1])
"""
parameters = {}
L = len(layer_dims)
for l in range(1,L):
parameters['W' + str(l)] = np.random.randn(layer_dims[l], layer_dims[l-1]) / np.sqrt(layer_dims[l-1]) #*0.01
parameters['b' + str(l)] = np.zeros((layer_dims[l], 1))
assert(parameters['W' + str(l)].shape == (layer_dims[l], layer_dims[l-1]))
assert(parameters['b' + str(l)].shape == (layer_dims[l], 1))
return parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment