On Wed, 11 Dec 2024 at 19:15, Paul Royik <[email protected]> wrote: > > I try to use the bridge between sympy and numpy, namely, the lambdify > function. > > It looks ok, but there is an issue when I try to calculate the values of > x^(2/5) on the interval [-5,5]. > > Of course, for negative x, the value is nan, because, I guess, the root is > not real-valued. > How to make it real-valued?
You can use e.g. In [22]: lambdify(x, (sign(x)*abs(x)**(1/5))**2)([-2, -1, 0, 1, 2]) Out[22]: array([1.31950791, 1. , 0. , 1. , 1.31950791]) The real_root function gives a more complicated form: In [23]: real_root(x, 5)**2 Out[23]: ⎧ 2/5 2 ⎪│x│ ⋅sign (x) for im(x) = 0 ⎨ ⎪ 2/5 ⎩ x otherwise That one works as well but prints out warnings when lambdified. -- Oscar -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/sympy/CAHVvXxRfx6CfT8SNKyGGpSRAGAUjt0EPj3YMn_N_9UXz_UHcsg%40mail.gmail.com.
