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
0
votes
0 answers

Lambdify sympy expressions for scipy.optimize lead to 'Symbol' object has no attribute 'sin'

I try to convert a sympy expression to solve this expression with scipy.optimize.fsolve. This is a minimalistic example: import numpy as np import sympy as sy import scipy as sc import scipy.optimize as sc a=sy.symbols('a') G=sy.sin(a) test =…
Katoon
  • 65
  • 1
  • 6
0
votes
1 answer

sympy lambdify with sympy matrix and numpy vector inputs

I want to compute a symbolic gradient with sympy, e.g., import sympy as sym x, y, z = sym.symbols("x y z", real=True) T = sym.cos(x**2+y**2) gradT = sym.Matrix([sym.diff(T, x), sym.diff(T,y), sym.diff(T,z)]) Now I would like to create a lamddify…
Manuel Oliveira
  • 527
  • 5
  • 19
0
votes
1 answer

I want to lambdify a function written in sympy

In sympy I write a function like this: from sympy import * x, y = symbols('x y') def Func(x,y): return sin(x) + cos(y) All works fine, but I find no way to lambdify this, e.g. Func_lam = lambdify(x, y, Func) z = Func_lam(1,2) gives an error, it…
0
votes
2 answers

Why lambdify never stops?

x = symbols('x') ch = 'exp(cos(cos(exp((sin(-0.06792841536110628))**(-6.045461643745118)))))' f = lambdify(x, ch, "numpy") print(float(f(2))) It does not work, the programm is running and never ends(no error is issued). My goal is to avoid this…
axism
  • 1
0
votes
1 answer

Accessing contents of numpy.ndarray fields

I have created an ndarray from a sympy lambdify function in python and the actual values I need are tucked away within this array field of my result variable. To be clear, each index of array along axis=0 corresponds to the first derivative of a 7th…
J_code
  • 356
  • 1
  • 5
  • 17
0
votes
1 answer

rounding part of a sympy expression

I have a sympy symbolic expression that contains sin and cos. At the end of the code I use lambdify((Phi),function(Phi))(phi) but I'm getting many non-zero values because of the angle dependence which consists of several pi values, since sin(pi)…
arsenis
  • 23
  • 7
0
votes
0 answers

How can I get a 'broadcasted' (m,n) array from a (m,)-valued Sympy Matrix which should take a (n,) numpy array as an argument?

I have the following case: I defined a Sympy Matrix (Vector) which is a function of parameters in some, but not all elements. So e.g. take from sympy import * a = Symbol('a') M = Matrix([a,0]) Now I want this to be a function which takes numpy…
0
votes
1 answer

Keep the order of parameters fixed in sympy lambdify from free_symbols

When asking for a symbol .free_symbols I get something in curly braces (which is a set). If I use this set as list of arguments for lambdify of sympy it seems it is converted into a list. This is hinted in the doc but I suggest a warning to be…
Rho Phi
  • 1,182
  • 1
  • 12
  • 21
0
votes
2 answers

"Add" object has no attribute "sinh" error in numerical and symbolic expression?

Ultimately, my goal is to numerically differentiate the expression 'u' (see code) with respect to t, with respect to X and three times with respect to X. First idea was to just write the expression down numerically, providing arrays (linspaces) for…
Linde
  • 45
  • 4
0
votes
1 answer

sympy lamdify issue with large numbers

I have some issue using sympy.lambdify. I have a rather simple symbolic expression involving only square root, sine and cosine and some large numbers (which get generated by other parts of the program not shown here). Lambdify does work for single…
laolux
  • 1,445
  • 1
  • 17
  • 28
0
votes
0 answers

I want to feed a lambdify generated function with an array of values, how can i best do that?

I have generated a function with lambdify, and can only output values with the function if i specify all specific arguments, one by one. I want to be able to feed the function phi_num, with the q, numpy array. Like phi_num(q). I have tried change…
0
votes
1 answer

Python: determinant, matrix, can't convert expression to float

I'm writing a short program which should find value for which real and imaginary part of function are both zero. I don't understand why I get "can't convert expression to float" after running program. (Please forgive my messiness while writing the…
0
votes
1 answer

Error evaluating a derivative on Python (with .subs, .evalf and .lambdify)

I am trying to separately compute the elements of a Taylor expansion and did not obtain the results I was supposed to. The function to approximate is x**321, and the first three elements of that Taylor expansion around x=1 should be: 1 + 321(x-1) +…
0
votes
1 answer

Why does the lambdify function from sympy throw an error in my case?

The error lies with the lambdify function. It says syntax error for some reason. This is what is says exactly: File "D:\Anaconda\lib\site-packages\sympy\utilities\lambdify.py", line 434, in lambdify func = eval(lstr, namespace). The program…
0
votes
1 answer

Sympy Lambdify - solving for unknown variable from two inequalities

I have been successful solving for an unknown variable with solve() Code here: x = 1000 y = Symbol('y') w = 2.84 * x > x + y, 1.7 * y > x + y solve(w) Now I am trying to get the same result from a Pandas dataframe, unsuccessfully though. …
Josef
  • 41
  • 3
1 2 3 4
5