如何将多个输出变量组合在一起?

2024-05-15 01:52:20 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在ano中实现一个函数,将一个向量映射到一个向量,但是输出向量的每个维度都是手工指定的。如果我创建一个这样的函数:

import theano
import theano.tensor as T
x = T.dvector('x')
dx = 28.0 * (x[1] - x[0])
dy = x[0] * (10.0 - x[1]) - x[2]
dz = x[0] * x[1] - 8.0/3/0 * x[2]
f = theano.function([x],[dx,dy,dz])

然后f([1,2,3])给出{}作为输出,我希望它返回array([10.0, 23.0, -6.0])。这样做的方式是什么?在


Tags: 函数importas方式functiontheanoarray向量
2条回答

凯尔·卡斯特纳的另一个答案也行,但你可以让ano帮你做这个(我从你的例子中修正了除法为0):

import theano
import theano.tensor as T
x = T.dvector('x')
dx = 28.0 * (x[1] - x[0])
dy = x[0] * (10.0 - x[1]) - x[2]
dz = x[0] * x[1] - 8.0/3.0 * x[2]
o = T.as_tensor_variable([dx,dy,dz])
f = theano.function([x],o)
f([1,2,3])
# output array([ 28.,   5.,  -6.])

函数的输出只是一个numpy数组的列表-您可以执行np.array(f([1, 2, 3]))将输出列表转换为numpy向量。在

相关问题 更多 >

    热门问题