Converting a function from sympy to numpy (attribute error)

import numpy as np
import sympy as sym
from numpy import sin
from sympy import symbols, diff

func = lambda x: sin(x)
x    = symbols('x')
print diff(func(x),x)

This works if I replace my function with a polynomial or if I put the trigger function directly in the diff statement. But in this format, I get AttributeError: sin.

Basically, I think python cannot recognize func as just a trigger function that knows how to integrate symbolically. I could just have a simplex import sin, and then everything will work, but then I was stuck with func referring to sin in the sympy namespace, and there are future things that I want to do with func that require them to be defined using sin in the numpy namespace,

+3
source share
2 answers

SymPy, lambdify, , NumPy.

+1

, sympy. numpy - , , .

sin (x),

import sympy as sym
from sympy import sin, symbols, diff

x = symbols('x')
print diff(sin(x), x)

- , , . sympy , , .

0

All Articles