I would like to lamdify an array input with sympy. Here was my first attempt:
import sympy as sym
import numpy as np
# Load Data
data = np.loadtxt( "D:\data.r2023.c87.dat", skiprows=1)
# Access to columns
vza = data [:,2]
sza = data [:,4]
# var_psi is the array input
psi = (1/(np.cos(sza))) + (1/(np.cos(vza)))
var_tau, var_omega, var_psi = sym.symbols('var_tau var_omega var_psi', real = True)
sBetaFunc = sym.exp(-var_tau * var_psi)
sBeta = sym.lambdify(var_psi, sBetaFunc, modules=[“numpy”, "sympy"])
If I now try to call the function the following error appears:
>>> sBeta(psi)
>>> AttributeError: 'Mul' object has no attribute 'exp'
If I try it this way the following error appears:
>>> sBeta(*psi)
>>> TypeError: <lambda>() takes exactly 1 argument (79 given)
I read a lot about this problem. However, nothing seems suitable to my problem or my case.
I need this in a sympy function because I would like to use the diff function from sympy to differentiate some very complex functions.
Thank you in advanced.
Edit:
Now I tried this:
import sympy as sym
import numpy as np
from sympy.abc import w, x, y, z
sBetaFunc = sym.exp(-var_tau * x)
sBeta = sym.lambdify(x, sBetaFunc, modules=["sympy"])
Now a different error appears:
>>> sBeta(psi)
>>> ValueError: sequence too large; cannot be greater than 32