Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array{Float64,0} returned from scipy #680

Closed
sitnarf opened this issue Apr 12, 2019 · 2 comments
Closed

Array{Float64,0} returned from scipy #680

sitnarf opened this issue Apr 12, 2019 · 2 comments

Comments

@sitnarf
Copy link

sitnarf commented Apr 12, 2019

Hi,
I am new to Julia, but I think, this is bad. Check this out:

interp = pyimport("scipy.interpolate")
np = pyimport("numpy")
x = np.arange(0, 10)
y = np.exp(-xx/3.0)
f = interp.interp1d(x, y)
println(f(1))
#prints 0.716531

So far so good. But, why this happens?

println([f(1), f(2), f(3)])
println(f.(x))
# Both prints
# Array{Float64,0}[0.716531, 0.513417, 0.367879]
# Array{Float64,0}[1.0, 0.716531, 0.513417, 0.367879, 0.263597, 0.188876, 0.135335, 0.096972, 0.0694835, 0.0497871]

Versions:

PyCall: 1.91.1
Julia: 1.1.0
Scipy: 1.2.1
@coroa
Copy link

coroa commented Jul 19, 2019

Well, it's a faithful representation of the Python's interp1d return value.

The function f expects to be called on an array and thus interprets f(1) as in f(np.array(1)), a 0-dim numpy array, and then returns the interpolation as such. Just note the type of your construct

julia> typeof(f.(x))
Array{Array{Float64,0},1}

To interpolate at points 1, 2 and 3, you should use,

julia> f([1,2,3])
3-element Array{Float64,1}:
 0.7165313105737893 
 0.513417119032592  
 0.36787944117144233

instead.

@sitnarf
Copy link
Author

sitnarf commented Jul 21, 2019

Thanks!

@sitnarf sitnarf closed this as completed Jul 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants