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
1
vote
1 answer

sympy lambdify with scipy curve_fit

I constructed a sympy expression and I used lambdify to convert to a numpy function as follow: import sympy from sympy.parsing.sympy_parser import parse_expr x0,x1 = sympy.symbols('x0 x1') a,b,c = sympy.symbols('a b c') func=parse_expr('a*x0 + b*x1…
aeonlea
  • 11
  • 3
1
vote
0 answers

Lambdify not working in Google Colaboratory

I've recently tried running the lambdify function, based on SymPy, on Google Colab, but am not having any success. The same code works on Spyder and Jupyter Notebook, but still no luck. Link to code:…
1
vote
1 answer

Sympy lambdify ImmutableDenseMatrix with numexpr

I try to accelerate the evaluation of a MutableDenseMatrix using lambdify. It works with the module 'numpy'. 'Numexpr' should be faster (as I need the evaluation to solve a large optimization problem). A smaller example of what I am trying to do is…
Franzi
  • 33
  • 5
1
vote
1 answer

How to efficiently lambdify a sparse matrix?

I am using sympy to build a sparse (N^2 x N^2) matrix and trying to convert it to a sparse scipy matrix. It is used in a finite difference method to solved Schrödinger equation on 2D grid depending on a k-vector k = (kx, ky). Dense Matrix to…
Ben
  • 13
  • 4
1
vote
1 answer

Lambdifying a function with conditon statements using sympy

Im trying to lambdify this function def f(x): if ceil(x)%2 == 0: return -1 else : return +1 a = sympy.lambdify(x,f(x)) Im getting an error when i try to do that. I also tried piecewise , but it is not giving me the desired…
Athul Dev
  • 61
  • 5
1
vote
1 answer

numpy.linalg.eigh works with numpy array from sym.lambdify() but not from np.array()

Here's the code. 2a works but 2b does not, even though both matrices have the same shape and the same type. Can anybody explain? import sympy as sym import numpy as np x1, x2 = sym.symbols('x1 x2') f = 2*x1**2 - 2*x1*x2 + x2**2 + 2*x1 - 2*x2 …
Alan M
  • 13
  • 3
1
vote
0 answers

How to evaluate the lambdify function for this example?

I'm new to Python. I trying Sympy and Numpy. I have this expression in sympy as follows x, n = symbols('x n') expression = (2/n)*sin(n*x) f = lambdify( [x,n], expression, "numpy") f(a,b) x value ranges are like say a = numpy.linspace(0,numpy.pi) n…
Venus8588
  • 15
  • 6
1
vote
1 answer

sympy lambdify with function arguments in tuple?

Suppose you have computed fu as a result of a sympy calculation: fu= sy.cos(x)+sy.sin(y)+1 where x,y = sy.symbols("x y") are symbols. Now you want to turn fu to a numpy function of (obviously) two variables. You can do this by: fun=…
geom
  • 195
  • 8
1
vote
1 answer

Lambda of a lambdified function whose argument is a function

I am currently trying to create a lambda function that will pass a variable to both a function that is a input to a lambdified function and to the lambdified function itself. My Python version is 2.7, and my sympy version is 1.3. I am able to have…
1
vote
1 answer

Python - Dot product for matrices doesn't seem to work when using sympy and lambdify

I'm implementing a data processing flow in python. I'm trying to use symbolic calculations (sympy and numpy) as much as possible to have clear documentation consistent with the code. So when I try to get dot product and use it for real matrices (by…
Ant
  • 63
  • 8
1
vote
1 answer

How to compute derivatives with Lambdify and IndexedBase in sympy

I am investigating the suitability of SymPy for some of my projects and have come across an issue with the interaction between lambdify and IndexedBase. In short, my applications make heavy use of functions that employ doubled summed array…
Daniel
  • 385
  • 1
  • 4
  • 12
1
vote
0 answers

Python: elegant way to use container in lambdified sympy expression

Say I have a container class containing some numeric value: class Container: def __init__(self, value): self.value = value I would like to give those Containers to a lambdified sympy expression and as a result get a new…
Safron
  • 802
  • 1
  • 11
  • 23
1
vote
2 answers

Sympy: Lambdify function with large array input

I have a problem lambdifing a function that expects a large array. A simplified code replicating the same problem is: from sympy import * def fun(x): f = [] for i,x_i in enumerate(x): f.append(x_i**i) return Matrix(f) N = 256 x =…
user42961
  • 93
  • 4
1
vote
1 answer

SyntaxError converting sympy expression to a python function

I am trying to convert the sympy expression for q_IN_w_sym (very long expression that can't be accommodated here) into a python function so I can evaluate its numerical value. I checked the number of symbols in q_IN_w_sym by using…
user11
  • 191
  • 1
  • 3
  • 11
1
vote
1 answer

lambdified sympy expression returns incorrect result

I encountered following problem, first I will explain briefly what is going on: f(x) g(x, y) = f(x) - y From there we expect g(x, f(x)) = f(x) - f(x) = 0 lambdified g(x,y) returns something very close to zero instead of zero. Here's a code that…
Marek
  • 1,413
  • 2
  • 20
  • 36