Theano gives TypeError: 'Add' object is not iterable
Theano gives TypeError: 'Add' object is not iterable
我在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
感谢您的帮助。
我尝试将 f
包含在 theano_function
中的列表中并且 运行 没有错误。让我知道它是否提供了您想要的输出。
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})
我在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
感谢您的帮助。
我尝试将 f
包含在 theano_function
中的列表中并且 运行 没有错误。让我知道它是否提供了您想要的输出。
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})