I am using anaconda on linux, I have installed related packages. I am trying to learn theano, for simplicity I want to run the following codes
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)
following the question in here . However, I get the following error:
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
Thanks for any help.
I tried enclosing f
into a list in the theano_function
and it ran without errors. Let me know if it gives the output you want.
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})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.