use*_*343 8 python numpy theano
我有简单的代码,如下所示:
class testxx(object):
def __init__(self, input):
self.input = input
self.output = T.sum(input)
a = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype = np.float32)
classfier = testxx(a)
outxx = classfier.output
outxx = np.asarray(outxx, dtype = np.float32)
Run Code Online (Sandbox Code Playgroud)
但是,我收到以下错误信息:
ValueError: setting an array element with a sequence.
Run Code Online (Sandbox Code Playgroud)
此外,当我使用theano.tensor的函数时,似乎它返回的内容称为"tensor",我不能简单地将它切换到numpy.array类型,即使结果应该像矩阵一样形状.
所以这是我的问题:如何切换outxx键入numpy.array?
Theano“张量”变量是符号变量。您用它们构建的内容就像您编写的程序一样。您需要编译一个 Theano 函数来执行该程序的功能。有两种编译 Theano 函数的方法:
f = theano.function([testxx.input], [outxx])
f_a1 = f(a)
# Or the combined computation/execution
f_a2 = outxx.eval({testxx.input: a})
Run Code Online (Sandbox Code Playgroud)
当你编译 Theano 函数时,你必须知道输入是什么和输出是什么。这就是为什么在调用 theano.function() 时有 2 个参数。eval() 是一个接口,它将在给定的符号输入上编译并执行具有相应值的 Theano 函数。
归档时间: |
|
查看次数: |
11798 次 |
最近记录: |