Skip to content

Instantly share code, notes, and snippets.

@muhammadgaffar
Created October 24, 2018 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muhammadgaffar/e32270c9d8001ed883a980e8e8ac58c5 to your computer and use it in GitHub Desktop.
Save muhammadgaffar/e32270c9d8001ed883a980e8e8ac58c5 to your computer and use it in GitHub Desktop.
def dictionary_to_vector(parameters):
"""
Roll all our parameters dictionary into a single vector satisfying our specific required shape.
"""
keys = []
count = 0
params = []
num_params = len(parameters)//2
for l in range(1,num_params+1):
params = params + ["W"+str(l)]
params = params + ["b"+str(l)]
for key in params:
# flatten parameter
new_vector = np.reshape(parameters[key], (-1,1))
keys = keys + [key]*new_vector.shape[0]
if count == 0:
theta = new_vector
else:
theta = np.concatenate((theta, new_vector), axis=0)
count = count + 1
return theta, keys
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment