Hi jtaylor74, On Mon, Feb 9, 2009 at 6:43 PM, jtaylor74 <jetaylo...@gmail.com> wrote: > > I don't know if this is a bug or not, but what I want is to evaluate a > lambdify'ed expression at a numpy.ndarray of points. > > Python 2.5.2 (r252:60911, Jul 31 2008, 17:28:52) > [GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. >>>> import numpy as np >>>> from sympy import Symbol, Piecewise, lambdify >>>> >>>> t=Symbol('t') >>>> f=Piecewise((0, t<3), (t,(t<4)), (1,t>=4)) >>>> fl = lambdify(t, f) >>>> >>>> print [fl(float(_t)) for _t in np.linspace(0,10,11)] > [0, 0, 0, 3.00000000000000, 1, 1, 1, 1, 1, 1, 1] >>>> print [fl(_t) for _t in np.linspace(0,10,11)] > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "<string>", line 1, in <lambda> > File "/home/jtaylo/code/virtualenv/nipy/lib/python2.5/site-packages/ > sympy-0.6.3-py2.5.egg/sympy/functions/elementary/piecewise.py", line > 69, in __new__ > " Relational or Number" % (ec[1], cond_type) > TypeError: Cond True is of type <type 'numpy.bool_'>, but must be a > bool, Relational or Number >>>> >>>> import numpy.version >>>> print numpy.version.version > 1.2.0 > >>>> import sympy >>>> print sympy.__version__ > 0.6.3 >>>>
I can reproduce it with the latest git version: In [1]: import numpy as np In [2]: t=Symbol('t') In [3]: f=Piecewise((0, t<3), (t,(t<4)), (1,t>=4)) In [4]: fl = lambdify(t, f) In [5]: print [fl(float(_t)) for _t in np.linspace(0,10,11)] [0, 0, 0, 3.00000000000000, 1, 1, 1, 1, 1, 1, 1] In [6]: print [fl(_t) for _t in np.linspace(0,10,11)] --------------------------------------------------------------------------- TypeError Traceback (most recent call last) /home/ondra/repos/sympy/<ipython console> in <module>() /home/ondra/repos/sympy/<string> in <lambda>(t) /home/ondra/repos/sympy/sympy/functions/elementary/piecewise.pyc in __new__(cls, *args, **options) 69 raise TypeError, \ 70 "Cond %s is of type %s, but must be a bool," \ ---> 71 " Relational or Number" % (ec[1], cond_type) 72 73 # sympify args TypeError: Cond True is of type <type 'numpy.bool_'>, but must be a bool, Relational or Number So I think it's a bug. Thanks a lot for reporting it. The problem is with this code: if not (cond_type is bool or issubclass(cond_type, Relational) or \ issubclass(cond_type, Number)): raise TypeError, \ "Cond %s is of type %s, but must be a bool," \ " Relational or Number" % (ec[1], cond_type) It checks for bool, but not numpy.bool_. Does anyone know how to make it, so that it works with numpy types, but doesn't use numpy.bool_ explicitely? Ondrej --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to sympy@googlegroups.com To unsubscribe from this group, send email to sympy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---