#coding=utf-8 """ Symbolic computation of python theano @Author: zhang zewang @Date: 2016-3-2 """ import sys sys.path.append('../utils/') import theano import theano.tensor as T import numpy as np from functionUtils import shared_normal,shared_zeros w = 1.5 def step(input): return w*input input = T.dscalar('input') output = step(input) f = theano.function([input],[output]) gf = T.grad(output,input) gf = theano.function([input],[gf]) i = 4 print f(4) print gf(4)
#coding=utf-8 """ Symbolic computation of python theano @Author: zhang zewang @Date: 2016-3-2 """ import sys sys.path.append('../utils/') import theano import theano.tensor as T import numpy as np from functionUtils import shared_normal,shared_zeros w = [[1.5,2],[3,4]] w = np.array(w) input = T.dmatrix('input') output = w*(input) f = theano.function([input],[output]) gf = T.grad(output.sum(),input) gf = theano.function([input],[gf]) i = [[1,2],[5,6]] print f(i) print gf(i)
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/8072.html