Skip to content

Instantly share code, notes, and snippets.

@akarsh-saxena
Created May 21, 2020 21:38
Show Gist options
  • Save akarsh-saxena/46363575bbc9eea388bf13e831ca6a76 to your computer and use it in GitHub Desktop.
Save akarsh-saxena/46363575bbc9eea388bf13e831ca6a76 to your computer and use it in GitHub Desktop.
import numpy as np
def update_weights(params, changes, learning_rate=0.01):
"""Updates weights of the layers
Arguments
---------
params: dict
Dictionary containing 'w' and 'b'
changes: dict
Dictionary containing 'dw' and 'db'
learning_rate: int, float
Learning rate for the weight update
Returns
-------
dict
Dictionary containing updated weights and biases
The keys for weights and bias arrays in the dict is 'w' and 'b'
"""
w = params['w']
b = params['b']
dw = changes['dw']
db = changes['db']
w -= learning_rate*dw
b -= learning_rate*db
return {'w': w, 'b': b}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment