【发布时间】:2015-11-02 18:41:53
【问题描述】:
我试图在与步骤相乘的同时累积矩阵值: res = sum_i(i * a)。我的代码如下所示:
import numpy as np
from theano import function, scan
import theano.tensor as T
x = T.lmatrix()
results, updates = scan(
lambda res, step, x: res + step * x,
non_sequences=x,
sequences=T.arange(2),
outputs_info=T.zeros_like(x))
f = function([x], results)
a = np.array([[0, 0], [2, 2]], 'int64')
print(f(a))
这个输出:
[[[0 0]
[0 0]]
[[1 1]
[1 1]]]
虽然我希望这样:
[[[0 0]
[0 0]]
[[0 0]
[2 2]]]
【问题讨论】:
-
我提供了一个答案,解释了为什么你得到了你实际得到的输出,但不能评论为什么这与你的期望不同,因为不清楚 为什么 你期望输出
[[[0 0] [0 0]] [[0 0] [2 2]]]。如果您用更多关于您的期望的信息更新问题,我也许可以用更多信息更新我的答案。
标签: theano