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
6
votes
3 answers

Converting hard integral to lambda function with lambdify

I would like to lambdify the function Integral(t**t,(t,0,x)). It works, but my new function, which was returned by lambdify, doesn't return a number but only sympy.integrals.integrals.Integral class. But I don't want that, I want it to return a…
lukas kiss
  • 381
  • 2
  • 15
5
votes
3 answers

Can I use lambdify to evaluate the derivative of a python function?

I asked a question yesterday regarding differentiating a python function and then when I found that none of the answers posted were satisfactory for my need of evaluating (in some variables) and then plotting the derivative, I was able to figure out…
user3843183
4
votes
1 answer

Use Lambdify for multiple symbolic variables

The python script below evaluates the first term in the expression, 4.939e-3xAxB+8.7989 at (A,B) = (1.0,1.0): import sympy from sympy import * A = sympy.Symbol(A) B = sympy.Symbol(B) F = 4.939e-3*A*B+8.7989 G = str(F).split("+")[0] H =…
flappingwings
  • 65
  • 1
  • 7
4
votes
1 answer

Optimizing runtime with lambdify and function evaluation

I am currently optimizing the runtime of my code, and it is still not within the time consumption bounds I would like it to be. I have gotten to the point where 80% of the time is spent on running lambdify() on my sympy Matrix expressions and…
dold
  • 49
  • 2
4
votes
1 answer

Error with sympy.lambdify for piecewise functions and numpy module

In sympy 0.7.6, I had no troubles with the following code for both the modules='sympy' and the modules='numpy' options. Now with sympy v0.1, the evaluation with modules='numpy' raise a ZeroDivisionError: import sympy x, y = sympy.symbols(['x',…
Toht
  • 53
  • 6
3
votes
2 answers

Python - Sympy - Solving equations numerically for multiple parameters in a grid

A given equation depends on an unknown variable (y) and a set of parameters. I would like to numerically solve for y, given each element of a grid with values of the parameters. A simplified example of my attempted solution is as follows (y is the…
CarlosH
  • 319
  • 1
  • 4
  • 8
3
votes
1 answer

Sympy to numpy causes the AttributeError: 'Symbol' object has no attribute 'cos'

I am trying to do partial derivatives using sympy and I want to convert it to a function so that I can substitute values and estimate the derivatives at some values of t_1, t_2. The code I am using is as follows: import sympy as sp import numpy as…
Vishnu
  • 499
  • 1
  • 5
  • 23
3
votes
2 answers

Lambdify works with Python, but throws an exception with Cython

My website runs this Python script that would be way more optimized if Cython is used. Recently I needed to add Sympy with Lambdify, and this is not going well with Cython. So I stripped the problem to a minimum working example. In the code, I have…
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
2
votes
0 answers

lambdify integral solution to inverse power law

I am using sympy to evaluate an integral of the form 1/t^p and then lambdify the expression to evaluate it. Evaluated at p=1, the resolution expression should return ln(t), but instead returns a ZeroDivisionError. I expect I will need to expand the…
2
votes
1 answer

Fourier series of a box function using sympy

I tried this code but i m getting an error. And If possible pls tell me how to lambdify the defined funct CODE from sympy.abc import x from sympy import * init_printing() def func(y): if y>0: return 1 elif y<0: return -1 …
Athul Dev
  • 61
  • 5
2
votes
1 answer

Converting sympy function to lambda function

I've been trying to convert my sympy function variable which looks like this:- (atan(−3/)+2.66602685430536⋅10−6)^2+(atan(−2/)−0.0896686524911619)^2+(atan(−1/)−0.16739555984988)^2 Function expression I've been trying to use lambdastr and lambdify for…
2
votes
3 answers

How do I use sympy.lambdify with Max function to substitute numpy.maximum instead of numpy.amax?

I'm trying to lambdify big analytic expression with sp.Max(x, 0) inside. I want to use numpy to vectorize my calculations, so x is going to be an array. I need element-wise maximum values of x and 0. Still, sympy changes sp.Max to np.amax by…
2
votes
1 answer

How can I use lambdify to evaluate my function?

I have an expression with several variables, let's say something like below: import numpy as np import sympy as sym from sympy import Symbol, Add, re, lambdify x = sym.Symbol('x') y = sym.Symbol('y') z = sym.Symbol('z') F = x+ y +z I have three…
Hey There
  • 275
  • 3
  • 14
2
votes
1 answer

Multiplying N matrices - symbolic calculation

What is the most efficient (quickest) way to multiply 20 identical 6x6 matrices (M)? N = 20 w = sy.Symbol("w");v = sy.Symbol("v");p = sy.Symbol("p");q = sy.Symbol("q");c = 1;n = 1;nc = 1 M = np.array([[w*p*q,w*q,0,0,0,0], …
uros bio
  • 23
  • 3
2
votes
0 answers

Lambifying Nested Parametric Integrals

I have a loss function L(u1,...,un) that takes the form L(u) = Integral( (I**2 + J**2) * h, (t,c,d) ) //h=h(t), I=I(t,u) where I = Integral( f, (x,a,b) ) // f=f(x,t,u) J = Integral( g, (x,a,b) ) // g=g(x,t,u) I want to numerically minimize L…
Hyperplane
  • 1,422
  • 1
  • 14
  • 28
1
2 3 4 5