In Julia you could do something like this:
using SymPy
@vars x y z
feature_names = [1, x, y, z, x^2, x*y, x*z, y^2, y*z, z^2]
f(a,b,c) = feature_names.evalf(subs=Dict(x=>a,y=>b,z=>c)) |> N |> vec
f(1,2,3) # [1.0,1.0,2.0,...]
or, more in general,:
solveMultipleSympyFunctions(values,sympy_symbols,expressions) = expressions.evalf(subs=Dict(zip(sympy_symbols,values))) |> N |> vec
solveMultipleSympyFunctions([1,2,3],[x,y,z],feature_names)
The N(.)
function is to retrieve a numerical output instead of a number that is still a symbol, and vec()
is to transform the output, that is in matrix form, to a vector as in your request. Finally, |>
is the pipe operator (just for convenience instead of writing vec(N(...))
)
EDIT:
I did try several ways to start the expressions from a vector of strings, but none of the above works:
feature_names_string = ["1", "x", "y", "z", "x^2", "x*y", "x*z", "y^2", "y*z", "z^2"]
feature_names = symbols.(feature_names_string)
feature_names = symbols.(Symbol.(feature_names_string))
feature_names = sympy.Function.(feature_names_string)
feature_names = convert.(Sym,sympy.Function.(feature_names_string))
feature_names = Sym(feature_names_string)
feature_names = Sym.(feature_names_string)
feature_names = Sym.(sympy.Function.(feature_names_string))
feature_names = sympy.Function.(Sym.(feature_names_string))