As a JavaScript developer Python scoping doesn't make sense at all. Just came across this example. Just to give a peek:
def policy_backward(eph, epdlogp):
""" backward pass. (eph is array of intermediate hidden states) """
dW2 = np.dot(eph.T, epdlogp).ravel()
dh = np.outer(epdlogp, model['W2'])
dh[eph <= 0] = 0 # backpro prelu
dW1 = np.dot(dh.T, epx)
return {'W1':dW1, 'W2':dW2}
The question is: how this function will have access to epx
? It is not a global variable (but as I know, you couldn't anyways without defining it global
inside the function body), it is not initialized inside the function, and it is not defined inside it's parameters. So how will it get access to it?
Was trying to somehow reproduce the logic:
def a():
x = x or 3
x += 1
def b():
x = 3
a()
print(x)
b()
But getting x
referenced before assigned no matter what I do.