Reputation: 63
I have an array of numbers of which I want to calculate values with a simple equation.
import numpy as np
import sympy as sym
x_values = np.linspace(0, 2, 100)
function = lambda x : 10*sym.sin(9*x)
function(x_values)
I get:
AttributeError: 'ImmutableDenseNDimArray' object has no attribute 'could_extract_minus_sign'
Upvotes: 2
Views: 413
Reputation: 3993
You should define a function
import numpy as np
import sympy as sym
x_values = np.linspace(0, 2, 100)
def function(x):
lambda x : 10*sym.sin(9*x)
return x
print(function(x_values))
The code:http://tpcg.io/cBEnHu or you can do this
import numpy as np
from sympy import sin
import pylab as pl
from sympy.abc import x
from sympy import Function
from sympy import *
x_values = np.linspace(0, 2, 100)
function = lambdify(x, 10*sin(9*x))
print(function(x_values ))
The code:http://tpcg.io/cBEnHu
Upvotes: 0
Reputation: 10437
You can do this using sympy.lambdify
, like this:
import numpy as np
import sympy as sym
x = sym.symbols("x")
x_values = np.linspace(0, 2, 100)
function = sym.lambdify(x, 10*sym.sin(9*x), "numpy")
function(x_values)
Upvotes: 2