示例代码1:
import theano
from theano import tensor
x = tensor.vector("x")
y = tensor.vector("y")
w = tensor.vector("w")
z = tensor.vector("z")
z = x+y+w
f = theano.function([x, theano.In(y, value=[1,1,1]), theano.In(w,value=[2,2,2], name='weights')], z)
# 不使用默认值
print( f([1,2,3], [2,3,4], [3,4,5]) )
# 使用默认值
print( f([1,2,3], [2,3,4]) )
print( f([1,2,3], weights=[2,3,4]) )
print( type(f([1,2,3], weights=[2,3,4])) )
运行结果:
示例代码2:(与示例代码1不同的地方在于设置变量数据类型为int而不是默认的double,即vector和ivector的区别)
import theano
from theano import tensor
x = tensor.ivector("x")
y = tensor.ivector("y")
w = tensor.ivector("w")
z = tensor.ivector("z")
z = x+y+w
f = theano.function([x, theano.In(y, value=[1,1,1]), theano.In(w,value=[2,2,2], name='weights')], z)
# 不使用默认值
print( f([1,2,3], [2,3,4], [3,4,5]) )
# 使用默认值
print( f([1,2,3], [2,3,4]) )
print( f([1,2,3], weights=[2,3,4]) )
print( type(f([1,2,3], weights=[2,3,4])) )
运行结果:
标签:tensor,框架,示例,grandfather,weights,print,theano,ivector From: https://www.cnblogs.com/devilmaycry812839668/p/18013705