UnboundLocalError: local variable 'e1' referenced before assignment

It’s because A.dtype is object. theano does not know how to apply the dot product on an array of objects. It can only handle numerical values, such as float32, float64, int32, etc. If you could change the dtype of A to make something like this: A = np.empty(shape=(T_time,S), dtype=np.float) and a_row = np.zeros(shape=S, dtype=np.float), you should be fine. If you can’t change the A's datatype, then you wont be able to use it.