给出以下代码:
import numpy as np
import theano
import theano.tensor as T
x,y,z = T.dmatrices('x','y','z')
A = theano.shared(np.random.rand(3,4), borrow=True, name='A')
B = theano.shared(np.random.rand(3,4), borrow=True, name='B')
f = x+y+B
有没有可能用表达式中的z+A代替y,这样它就等价于x+z+A+B?。它可以手动完成,方法是在图形中搜索y的出现,并用z+A替换它们。然而,在API中使用一种更简单的高级方法似乎是合乎逻辑的。在
这是discussed on the theano-users mailing list。在
您可以使用
theano.function
的givens
机制,也可以使用theano.clone
。在下面是一些示例代码:
注意,必须调整对theano函数的输入,以确保仅接受未指定的张量作为输入(即
y
一旦被z
函数所取代,它就不再是输入)。在相关问题 更多 >
编程相关推荐