Theano给出TypeError:'Add'对象不可迭代

时间:2019-03-28 11:34:30

标签: python sympy theano

我在Linux上使用anaconda,已经安装了相关软件包。 我正在尝试学习theano,为简单起见,我想运行以下代码

    from sympy.printing.theanocode import theano_function
    import sympy as sp
    import numpy as np

    x, y, z = sp.symbols('x y z')
    f = sp.sin(x)*sp.cos(y)*sp.sin(z) + sp.sin(4*(x - y**2*sp.sin(z)))
    xg, yg, zg = np.mgrid[0:1:50*1j, 0:1:50*1j, 0:1:50*1j]

    theano_f = theano_function([x, y, z], f, dims={x: 3, y: 3, z: 3})

    ######################### 
    In [1]: %timeit theano_f(xg, yg, zg)

遵循here中的问题。但是,出现以下错误:

  File "/home/user/anaconda3/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 786, in runfile
    execfile(filename, namespace)

  File "/home/user/anaconda3/lib/python3.6/site-packages/spyder_kernels/customize/spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "/home/user/desktop/scripts/Anaconda3pros/pros/den.py", line 9, in <module>
    theano_f = theano_function([x, y, z], f, dims={x: 3, y: 3, z: 3})

  File "/home/user/anaconda3/lib/python3.6/site-packages/sympy/printing/theanocode.py", line 235, in theano_function
    toutputs = list(map(code, outputs))

TypeError: 'Add' object is not iterable

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我尝试将var dicList = [{ student_id: 334, full_name: "student B", score: 9, class_id: 222 }, { student_id: 333, full_name: "student A", score: 7, class_id: 222 }] for (var i = 0; i < dicList.length; i++) { // move i++ to the end for (var key in dicList[i]) { if (dicList[i].hasOwnProperty(key)) { // use dicList[i] instead of test console.log(key, dicList[i][key]); } } }放入f的列表中,并且运行无误。让我知道它是否提供您想要的输出。

theano_function