f_mean = lambdify([mu, sigma], mean, modules='numpy')
where mean is a function of mu and sigma and mu and sigma are both arrays
mu = symbols('mu_0:%d' % n, real=True, bounded=True)
sigma = symbols('sigma_0:%d' % n, positive=True, real=True, bounded=True)
Under Python 2.7.5+ SymPy 0.12.0 I can use:
y = f_mean(x_n, ux_n)
returning y as a numpy array of size n when x_n and ux_n are both numpy arrays of size n.
However, with Python 3.3.2+ and SymPy 0.7.4.1-git I get (for n=5):
y = f_mean(x_n, ux_n)
TypeError: <lambda>() missing 10 required positional arguments: 'mu_2', 'mu_3', 'mu_4', 'mu_5', 'sigma_0', 'sigma_1', 'sigma_2', 'sigma_3', 'sigma_4', and 'sigma_5'
Which is similar to what I got in Python 2.7 before I added the modules=numpy argument
All this on ubuntu 13.10
Have I missed something in the docs or did I stumble on a not yet implemented feature?
Any help very welcome.heers,
Cheers, Janwillem
import sympy
import numpy
n = 2
formula = 'x_0 + x_1'
x = sympy.symbols('x_0:%d' % n, real=True, bounded=True)
y = sympy.sympify(formula)
fx = f_x = sympy.lambdify([x], y, modules='numpy')
X = numpy.ones(n)
print('function value=', fx(X))
Python 2.7 returns:
('function value=', 2.0)
which is obviously the correct answer.
Python 3.3 returns:
print('function value=', fx(X))
TypeError: <lambda>() missing 1 required positional argument: 'x_1'
import sympy
import numpy
n = 2
x = sympy.symbols('x_0:%d' % n, real=True, bounded=True)
formula = 'x_0 + x_1'
y = sympy.sympify(formula)
fx = f_x = sympy.lambdify(x, y, modules='numpy')
X = numpy.ones(n)
print('function value=', fx(*X)) # works on both pythons
a = sympy.symbols('a_0:%d' % n, real=True, bounded=True)
formula = 'a_0 * x_0 + a_1 * x_1'
y = sympy.sympify(formula)
fx = f_x = sympy.lambdify([x, a], y, modules='numpy')
a = numpy.linspace(0.5, 1.0, n)
print('function value=', fx(*[X, a])) # does not work on 3.3
gives with 3.3
print('function value=', fx(*[X, a]))
TypeError: <lambda>() missing 2 required positional arguments: 'a_0' and 'a_1'
_f_x = sympy.lambdify([x, a], y)
def f_x(x, a):
return _f_x(*numpy.hstack([x, a]))
This works on Python3.3 but now I get on Python2.7:
Traceback (most recent call last):
File "sympy-numpy_2.py", line 39, in <module>
print('function value=', f_x(X, a))
File "sympy-numpy_2.py", line 36, in f_x
return _f_x(*numpy.hstack([x, a]))
TypeError: <lambda>() takes exactly 2 arguments (4 given)