I would like to evaluate symbolic expression with np array
example:
import numpy as np
a = np.array([1]*4)
b = np.array([2]*4)
res = repr(a) + ' + ' + repr(b)
value = eval(res)
error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'array' is not defined
I have a workaround but I will know if I can solve my initial problem
workaround found on stackoverflow Python eval function with numpy arrays via string input with dictionaries
formula = 'x+y'
res = eval(formula,{'x':a, 'y':b})
Edit:
in order to solve the problem add the array definition in the import module
from numpy import array