gpt4 book ai didi

python - 如何在 Theano 中将多个输出变量组合在一起?

转载 作者:行者123 更新时间:2023-11-28 22:48:26 25 4
gpt4 key购买 nike

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

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), array(23.0), array(-6.0)] 作为输出,当我希望它返回 array([10.0, 23.0, -6.0]) 时。这样做的 Theanic 方法是什么?

最佳答案

Kyle Kastner 的另一个答案会起作用,但您可以让 Theano 为您做这个(我从您的示例中将除数固定为 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.])

关于python - 如何在 Theano 中将多个输出变量组合在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25143328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com