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

  attributeerror, lambdify, python, scipy, sympy

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 = sy.lambdify(a,G,"numpy") #also "sympy" will not help
sc.fsolve(test,a)

I will get the following error

AttributeError: 'Symbol' object has no attribute 'sin'
TypeError: loop of ufunc does not support argument 0 of type Symbol which has no callable sin method

I use python (3.8.10), numpy (1.20.2), sympy (1.8) and scipy (1.6.2). Some discussions attribute this to a namespace issue, but that shouldn’t be the case here.
Can someone explain me what I’m doing wrong?

Source: Python Questions

LEAVE A COMMENT