Questions tagged [lambdify]

Module lambdify of sympy package provides convenient functions to transform sympy expressions to lambda functions which can be used to calculate numerical values

Module lambdify provides convenient functions to transform sympy expressions to lambda functions which can be used to calculate numerical values.

For more information look for sympy documentation about Lambdify module.

75 questions
2
votes
2 answers

Python How to get the value of one specific point of derivative?

from sympy import * x = Symbol('x') y = x ** 2 dx = diff(y, x) This code can get the derivative of y. It's easy dx = 2 * x Now I want to get the value of dx for x = 2. Clearly, dx = 2 * 2 = 4 when x = 2 But how can I realize this with python codes?…
Bin
  • 209
  • 1
  • 3
  • 8
2
votes
1 answer

lambdification of sympy piecewise function evaluates every expression

I'm lambdifying a sympy piecewise function trying to do something like this: f = Piecewise((1,(p > -1e-10) & (p < 1e-10)), (1/p, True)) g = lambdify(p,f,"numpy") While >>> f.subs(p,0) 1 I get >>>…
pyrogen
  • 209
  • 1
  • 7
2
votes
1 answer

How to lambdify an Intersection

I am inverting a function with the invert_real from sympy.solvers.solveset, because neither solve nor solveset can do it for some reason. The result is an Intersection and seems to be correct. I now want to use it for numeric calculations. When I…
Noldi
  • 23
  • 2
2
votes
1 answer

sympy lambdify add two functions

I have two functions created with sympy's lamdify a = sympy.lambdify((x, y), K / (2 * math.pi) * sympy.cos(theta) / r) b = sympy.lambdify((x, y), -G / (2 * math.pi) * theta) How can I create a new function that is the addition of these two…
Devin Crossman
  • 7,454
  • 11
  • 64
  • 102
2
votes
1 answer

lambdify to py function: How to maintain the order of symbols constant

I have some symbolic expressions that I have stored in a text file (because they are too large) to read them later in order to find their numerical estimates. So, after I read those expressions (say foo_sym), I convert those expressions into python…
user11
  • 191
  • 1
  • 3
  • 11
2
votes
1 answer

sympy lambdify: how to make more functions (NCDF, NPDF, etc) available

How do I make sympy’s lambdify accept more function names, like a Normal function, for example? To make something like this work: lambdify(('x',), 'NPDF(x, 0, 1)') I don’t mind using the Normal function from the sympy statistics module, as long as…
taylor swift
  • 2,039
  • 1
  • 15
  • 29
2
votes
1 answer

Sympy Complex Expression To Python Function

I found documentation for lambdify on the sympy website here: http://docs.sympy.org/dev/modules/utilities/lambdify.html Trying examples with complex numbers seems to fall apart: SympyExpression =…
D A
  • 3,130
  • 4
  • 25
  • 41
2
votes
1 answer

How to make a Sympy lambdify(ed) function accept array input?

I’m trying to create a function in Python 2.7 that accepts a function handle and the number of variables in the function as the input and returns a new function that calculates the gradient of the input function. This is what I have so far. import…
1
vote
2 answers

Can SymPy Lambdify translate core functions like Add and Mul?

My goal is to evaluate a basic symbolic equation such as ad(b + c) with my own custom implementaions of multiply and addition. I'm trying to use lambdify to translate the two core SymPy functions (Add and Mul) with my own functions, but I cant get…
xareth
  • 112
  • 9
1
vote
2 answers

pure sympy: "loop of ufunc does not support argument 0 of type Mul which has no callable log method"

I am confused by sympy. First some setup. I entered the following into a python console >>> import sympy as smp >>> x, y = smp.symbols('x y', real=True) >>> f = smp.log(x) + y followed by >>> smp.lambdify(x, f)(1) y which makes sense to me. Then I…
midi3
  • 13
  • 3
1
vote
1 answer

Lambdify-ing an expression with several variables using a single lambda x

Imagine you have the following sympy expression: '1.0 * H * L * * 3 * W * *2' which contains the sp.Symbols variables=[H, L and W]. if this expression is lambdify-ed using sp.lambdify([sp.Symbol(vari) for vari in variables],'1.0 * H * L * * 3 * W *…
adrckul
  • 43
  • 3
1
vote
1 answer

sympy-lamdify can't convert "And"

I am trying to remap And in sympy when using lambdify, but it seems not working... import sympy x, y = sympy.symbols('x y') f = sympy.And(x, y) def my_and(x, y): print("inside my_and") return x and y f_fn = sympy.lambdify([x, y], f,…
DustDuck
  • 11
  • 1
1
vote
2 answers

How to lambdify a list of strings with SymPy in Julia?

Using SymPy in Julia, how can I transform the example input feature_names = ["1", "x", "y", "z", "x^2", "x y", "x z", "y^2", "y z", "z^2"] into a callable method f(x, y, z) which returns the evaluation of the expressions like julia >>> f(1, 2,…
Felix
  • 83
  • 9
1
vote
0 answers

How to covert a Python function to SymPy?

I want to convert a function defined in Python to a symbolic expression in SymPy (lambdify does the opposite): import numpy as np import sympy as sp def fun1(t): return t + 3 def fun2(t): return np.sin(t) And then convert this fun1 and fun2…
Tito Diego
  • 47
  • 1
  • 6
1
vote
1 answer

Converting sympy expression to numpy expression before solving with fsolve( )

I have a system of equations expressed by sympy: def test1a(A): t, tt = sym.symbols('t tt') return sym.cos(t+tt+A)*A def test1b(B): t, tt = sym.symbols('t tt') return sym.sin(t-tt+B)*B That I want to convert to a numpy expression…
t.o.
  • 832
  • 6
  • 20