Reputation: 2005
I have imported scipy.interpolate.Rbf
from python to Julia 1.6
using PyCall
. It works, but when I am trying to assign the radial function value to multiquadric
it doesn't allow me to do so, due to syntax issue. For example:
using PyCall
interpolate = pyimport("scipy.interpolate")
x = [1,2,3,4,5]
y = [1,2,3,4,5]
z = [1,2,3,4,5]
rbf = interpolate.Rbf(x,y,z, function='multiquadric', smoothness=1.0)
for the above example I am getting this error:
LoadError: syntax: unexpected "="
Stacktrace:
[1] top-level scope
This is due to the use of function
variable. May I know what can be the way around this error, so that i can assign the multiquadric
radial for the rbf.
Look forward to the suggestions.
Thanks!!
Upvotes: 2
Views: 57
Reputation: 42214
Your problem is that function
is a reserved keyword in Julia. Additionally, note that 'string'
for strings is OK in Python but in Julia you have "string"
.
The easiest workaround in your case is py""
string macro:
julia> py"$interpolate.Rbf($x,$y,$z, function='multiquadric', smoothness=1.0)"
PyObject <scipy.interpolate.rbf.Rbf object at 0x000000006424F0A0>
Now suppose you actually need at some point to pass function=
parameter?
It is not easy because function
is a reserved keyword in Julia. What you could do is to pack it into a named tuple using Symbol
notation:
myparam = NamedTuple{(:function,)}(("multiquadric",))
Now if you do:
some_f(x,y; myparam...)
than myparam
would get unpacked to a keyword parameter.
Upvotes: 2