# Python map\_coordinates() equivalent in Julia

**URL:** <https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461>\
**Category:** General Usage\
**Tags:** question, interpolations\
**Created:** [July 25, 2024, 10:14am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461 "2024-07-25T10:14:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 25, 2024, 10:14am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/1 "2024-07-25T10:14:52Z")

</div>

What would be julia equivalent of that python code ? I am using [map\_coordinates — SciPy v1.14.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html) function. Here `vals_r` ,`r_grid_stream_pix`and `theta_grid_stream_pix` are of type Matrix{Float64}.

```julia
vals_r = map_coordinates(vals_r, (r_grid_stream_pix, theta_grid_stream_pix),
            order=1, cval=np.nan)

```

I couldn’t understand solution given in topic [Equivalent of map\_coordinates in Julia](https://discourse.julialang.org/t/equivalent-of-map-coordinates-in-julia/5648/1).

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 25, 2024, 11:18pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/2 "2024-07-25T23:18:31Z")

</div>

For a Matrix{T} as input array, the function `map_coordinates` is defined as follows:

```julia
using Interpolations
import StaticArrays: SVector
function map_coordinates(input::Matrix{T}, coordinates::Vector{SVector{N, T}}; method=BSpline(Linear())) where {N,T}
    output = T[]
    itp = interpolate(input, method, OnCell())
    for coord in coordinates
        push!(output, itp[coord...])
    end
    output
end

```

`input` is a Matrix{T} of size (m,n), and its elements  
are the the values of a real function, f, defined on the planar rectangle [1, m] x [1,n], at the integer coordinates (i, j), i=1…m, j=1, …n.  
i.e. `input[i,j]=f(i, j)`.  
`coordinates` is a vector of planar coordinates (x,y), with x\in[1,m], y\in [1, n].  
`map_coordinates` evaluates the function f at these coordinates and pushes it values to output.

```julia
const Sv=SVector
input = [1.65 -1.35 -0.98;
           2.4 1.2 0.7;
           4.3 3.36 2.54;
          3.2 2.86 1.74]

```

Let us get the values at the indices for second column

```julia
julia> map_coordinates(input, [Sv(1.0,2), Sv(2,2.0), Sv(3,2), Sv(4,2)])
4-element Vector{Float64}:
 -1.35
  1.2
  3.36
  2.86

```

Retrieve the values at coordinates inside the rectangle on which the function is defined:

```julia
julia> coordinates=[Sv(1.1, 1.5), Sv(1.2, 1.89), Sv(3,2)]
julia> map_coordinates(input, coordinates)
3-element Vector{Float64}:
  0.31500000000000006
 -0.5495999999999999
  3.36

```

If at least a coordinate is outside this rectangle we get an error. The scipy function assigns a prescribed value, cval=0, to such coordinates. (we can add this to the above definition) .

```julia
julia> map_coordinates(input, [Sv(0.97, 1.2)])
ERROR: BoundsError: attempt to access 4×3 interpolate(::Matrix{Float64}, BSpline(Linear())) with element type Float64 at index [0.97, 1.2]

```

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 26, 2024, 4:03am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/3 "2024-07-26T04:03:16Z")

</div>

I am getting error as shown below.

```julia
ERROR: LoadError: MethodError: no method matching (::var"#map_coordinates#3"{var"#map_coordinates#1#4"})(::Matrix{Float64}, ::Tuple{Matrix{Float64}, Matrix{Float64}}; order::Int64, cval::Float64)

Closest candidates are:
  (::var"#map_coordinates#3")(::Matrix{T}, ::Array{SVector{N, T}, 1}; method) where {N, T} got unsupported keyword arguments "order", "cval"
   @ Main ~/Fluxes.jl:257

Stacktrace:
 [1] main()
   @ Main ~/Fluxes.jl:269
 [2] top-level scope
   @ ~/Fluxes.jl:349
in expression starting at /home/raman/Fluxes.jl:349

```

How to include `order` and `cval` values in function?

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 26, 2024, 5:24am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/4 "2024-07-26T05:24:18Z")

</div>

The error is caused by cval. In my definition of ‘map\_coordinates’ there is no kwarg, `cval`. You can modify the function code to assign to output a prescribed value, cval, corresponding to an outside coord.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 26, 2024, 9:49am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/5 "2024-07-26T09:49:51Z")

</div>

I tried adding keywords but i still gets error.

```julia
ERROR: LoadError: MethodError: no method matching (::var"#map_coordinates#3"{var"#map_coordinates#1#4"})(::Matrix{Float64}, ::Tuple{Matrix{Float64}, Matrix{Float64}})

Closest candidates are:
  (::var"#map_coordinates#3")(::Matrix{T}, ::Array{SVector{N, T}, 1}; method, order, cval) where {N, T}
   @ Main ~/Fluxes.jl:257

Stacktrace:
 [1] main()
   @ Main ~/Fluxes.jl:277
 [2] top-level scope
   @ ~/Fluxes.jl:357
in expression starting at /home/raman/Fluxes.jl:357

```

I also tried this modified code: 👇

```julia
    function map_coordinates(input::Matrix{T}, coordinates::Vector{SVector{N, T}}; method=BSpline(Linear()), order=1, cval=NaN) where {N,T}
        output = T[]
        itp = interpolate(input, method, OnCell())
        for coord in coordinates
            try
                push!(output, itp[coord...])
            catch e
                if isa(e, BoundsError)
                    push!(output, cval)
                else
                    rethrow(e)
                end
            end
        end
        output
    end

```

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 26, 2024, 1:08pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/6 "2024-07-26T13:08:21Z")

</div>

order is a keyword for the Python version. Here it isn’t necessary. Also `BoundsError` is thrown only when `method=BSpline(Linear())`. For `method=BSpline(Cubic())` it associates an interpolated value:

```julia
output=map_coordinates(input, [Sv(0.89, 1.2)];method=BSpline(Cubic()))
1-element Vector{Float64}:
 0.7674784494767151

```

Hence you should modify the code according to how you want to set the output (no matter which interpolation method is used), corresponding to a coord, exterior to the rectangle of definition.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 26, 2024, 3:04pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/7 "2024-07-26T15:04:12Z")

</div>

@empet I replaced `Cubic` and also removed `order=1, cval=nan` but i still have error 🥱

```julia
ERROR: LoadError: MethodError: no method matching (::var"#map_coordinates#3"{var"#map_coordinates#1#4"})(::Matrix{Float64}, ::Tuple{Matrix{Float64}, Matrix{Float64}})

Closest candidates are:
  (::var"#map_coordinates#3")(::Matrix{T}, ::Array{SVector{N, T}, 1}; method) where {N, T}
   @ Main ~/Fluxes.jl:257

Stacktrace:
 [1] main()
   @ Main ~/Fluxes.jl:277
 [2] top-level scope
   @ ~/Fluxes.jl:357
in expression starting at /home/raman/Fluxes.jl:357

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [July 26, 2024, 3:15pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/8 "2024-07-26T15:15:14Z")

</div>

I feel like you’ve been pointed to this in almost every single thread you’ve ever opened on this forum, but I’ll still do it again:

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

please read it carefully and take it to heart. Make sure that you post minimial, reproducible code snippets that yield the errors you are asking about. @empet has demonstrated how to use the function successfully, you are clearly running something else (the error comes from a `main()` function you are running, and shows that you are calling a function with a tuple of matrices as second argument when a vector of `SVector`s is required per the method definition.

Just blindly making superficial changes suggested by people on here into some different bit of code that you’re running but not showing really isn’t a good use of time for anyone.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 26, 2024, 3:57pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/9 "2024-07-26T15:57:21Z")

</div>

Input variables are of type Matrix{Float64}, but i gets error.

```julia
using Interpolations, StaticArrays
vals_r= rand(288,258)
r_grid_stream_pix= rand(1000,50)
theta_grid_stream_pix= rand(1000,50)

function map_coordinates(input::Matrix{T}, coordinates::Vector{SVector{N, T}}; method=BSpline(Cubic())) where {N,T}
        output = T[]
        itp = interpolate(input, method, OnCell())
        for coord in coordinates
            try
                push!(output, itp[coord...])
            catch e
                if isa(e, BoundsError)
                    push!(output, cval)
                else
                    rethrow(e)
                end
            end
        end
        output
    end
    vals_r = map_coordinates(vals_r, (r_grid_stream_pix, theta_grid_stream_pix))

```

I am getting error 👉

```julia
ERROR: MethodError: no method matching map_coordinates(::Matrix{Float64}, ::Tuple{Matrix{Float64}, Matrix{Float64}})

Closest candidates are:
  map_coordinates(::Matrix{T}, ::Array{SVector{N, T}, 1}; method) where {N, T}
   @ Main REPL[5]:1

Stacktrace:
 [1] top-level scope
   @ REPL[6]:1

```

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 26, 2024, 4:09pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/10 "2024-07-26T16:09:57Z")

</div>

You get that error because instead of coordinates which must be a Vector of of SVector(x,y), you pass a tuple of two matrices:

```julia
(r_grid_stream_pix, theta_grid_stream_pix)

```

Look at the examples given in my first answer to see how the coordinates are defined.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 27, 2024, 11:00am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/11 "2024-07-27T11:00:08Z")

</div>

I understand that it may be confusing as i am working on a lengthy script. My input variables are defined like this:

```julia
    theta_grid_stream_pix = ((theta_grid_stream_coord .+ theta[1]) ./ (2.0 * π .+ 2.0 * theta[1])) .* (2 * ntheta + 1)

    r_grid_stream_pix = similar(r_grid_stream_coord)
    for (i, j) in Tuple.(CartesianIndices(r_grid_stream_coord))
        r_val = r_grid_stream_coord[i, j]
        index = sum(r .< r_val) - 1
        if index < 1
            r_grid_stream_pix[i, j] = -1
        elseif index < nr - 1
            r_grid_stream_pix[i, j] = index + (r_val - r[index]) / (r[index + 1] - r[index])
        else
            r_grid_stream_pix[i, j] = nr
        end
    end

```

What should i do make them vector instead of Tuple as required by function? See attached file for detailed code. 👇  
[Fluxes.jl](https://discourse.julialang.org/uploads/short-url/hRWd6H2oBxHN1jKZ1nCKUxEyUYk.jl) (11.7 KB)

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 27, 2024, 1:29pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/12 "2024-07-27T13:29:09Z")

</div>

As long as we don’t know what problem is to be solved through the posted code it is difficult to suggest how to transform your data.

map\_coordinates is used in image processing for resampling images at non-integer position, i.e. for reconstruction of  
continuous intensity image from a discrete one.  
If the input array is interpreted as an image, then at each pixel (i,j) is stored its intensity, input[i,j].  
Coordinates is vector of non-integer positions where the intensity is to be evaluated through interpolation.

If your component matrices, in the tuple you posted, represent respectively the first and the second coordinate, then you should flatten them.  
If A is a matrix, vec(A) is its flattened version. Now if x is the vector representation of the first matrix, and y of the second one, then  
`coordinates=[SVector(a, b) for (a,b) in zip(x,y)]`.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 28, 2024, 10:50am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/13 "2024-07-28T10:50:10Z")

</div>

@empet This [folder](https://drive.google.com/drive/folders/1z2B6WZFIeDtrbI0lY4ielXzQWpgfc_U2?usp=sharing) contains library needed by my Julia script  
[Fluxes.jl](https://discourse.julialang.org/uploads/short-url/hRWd6H2oBxHN1jKZ1nCKUxEyUYk.jl) (11.7 KB).  
Please run it by modifying directory location to understand my problem. I want to get python [map\_coordinates — SciPy v1.14.0 Manual](https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.map_coordinates.html) function equivalent in Julia. I tried as far as i know with no success.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 29, 2024, 11:33am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/14 "2024-07-29T11:33:20Z")

</div>

The python version of `map_coordinates` works with input matrix of indices 0,1, \ldots, m-1, respectively 0,1\ldots,n-1.  
Hence the function f is evaluated at points within the rectangle [0,m-1]\times[0, n-1].

The coordinates at which the function f  
is to be evaluated are given in an odd way: `coordinates = np.array([[x1, x2], [y1, y2]])`, i.e. in the first row are x-coords and in the second one the y-coords.

Since Julia matrix indexing starts from 1, the function f is defined on [1,m]\times [1,n]  
Hence `coordinates =np.array([[x1, x2], [y1, y2])` must be converted to Julia  
`coordinates =[Sv(x1+1, y1+1), Sv(x2+1, y2+1)]`  
Let us check it. Take the second example from scipy manual:

```julia
from scipy.ndimage import map_coordinates
import numpy as np
a = np.arange(12.).reshape((4, 3))
inds = np.array([[0.5, 2], [0.5, 4]])
map_coordinates(a, inds, order=1, cval=-33.3)
array([2. , -33.3])

```

Note that here the function f is evaluated at the points  
(x,y)=(0.5, 0.5)\in [0, 2], and (x,y)=(2,4), with x=2\in [0,2], but y=4 \notin [0,2].  
That’s why the value at the last point is set on cval=-33.3.

JUlia corresponding code:

```julia
const Sv=SVector
a=[0.0 1 2;
   3 4 5;
   6 7 8]

inds = [Sv(0.5+1, 0.5+1), Sv(2.0+1, 4+1)] 
map_coordinates(a, inds; cval=-33.3) # map_coordinates is the Julia version that tests for BoundsError
2-element Vector{Float64}:
   2.0
 -33.3

```

The kwarg order from python version is replaced by method in Julia.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 29, 2024, 1:04pm UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/15 "2024-07-29T13:04:42Z")

</div>

If you are interested only in translating to Julia, a Python code involving `map_coordinates` then it’s better to define  
the input matrix as an OffsetMatrix:

```julia
function map_coordinates(input::OffsetMatrix{T, Matrix{T}}, coordinates::Vector{SVector{2, T}}; 
        method=BSpline(Linear()), cval=0.0) where T<:Real

```

and call it in the case of the given example from scipy manual, as follows:

```julia
using OffsetArrays
const Sv=SVector

a=[0.0 1 2;
3 4 5;
6 7 8]
m, n = size(a)
inds = [Sv(0.5, 0.5), Sv(2.0, 4)]
map_coordinates(OffsetArray(a, 0:m-1, 0:n-1), inds; cval=-33.3)  
2-element Vector{Float64}:
   2.0
 -33.3

```

With input matrix defined as an OffsetMatrix with indices from 0, it works similar to python, without adding 1 to each coordinate, because the rectangle of definition of the function resulted from interpolation is [0,m-1]\times[0,n-1].

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 31, 2024, 3:15am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/16 "2024-07-31T03:15:36Z")

</div>

@empet I am still getting error:

```julia
ERROR: LoadError: MethodError: no method matching (::var"#map_coordinates#3"{var"#map_coordinates#1#4"})(::Matrix{Float64}, ::Tuple{Matrix{Float64}, Matrix{Float64}})
Stacktrace:
 [1] main()
   @ Main ~/Fluxes.jl:278
 [2] top-level scope
   @ ~/Fluxes.jl:358
in expression starting at /home/raman/Fluxes.jl:358

```

and my modified code is 👇

```julia
#### Define map_coordinates() in julia
    function map_coordinates(input::OffsetMatrix{T, Matrix{T}}, coordinates::Vector{SVector{2, T}}; 
        method=BSpline(Linear()), cval=0.0) where T<:Real
        output = T[]
        itp = interpolate(input, method, OnCell())
        for coord in coordinates
            try
                push!(output, itp[coord...])
            catch e
                if isa(e, BoundsError)
                    push!(output, cval)
                else
                    rethrow(e)
                end
            end
        end
        output
    end
    
    # Join vector data through boundaries
    vals_r = hcat(vals_r_left[:, 1:1], vals_r_right, vals_r_left[:, end:-1:1], vals_r_right[:, 1:1])
    print(typeof(theta_grid_stream_pix))
    vals_r = map_coordinates(vals_r, (r_grid_stream_pix, theta_grid_stream_pix))

```

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [July 31, 2024, 4:51am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/17 "2024-07-31T04:51:56Z")

</div>

And it is also still the same error message.  
You pass as a second argument a `Tuple` but the method expects a `Vector`. That is the same error as 5 days ago. Not that emmets second argument `inds` is a **vector** of `SVectors`.  
Your second argument – note the round brackets – `(r_grid_stream_pix, theta_grid_stream_pix)` is a **Tuple**

As mentioned above and in several other of your threads. Please put in a bit more effort than just copying code that is answered to just post the error message to et us continue completely coding your problem or to quote from above

> [@nilshg](#):
>
> Just blindly making superficial changes suggested by people on here into some different bit of code that you’re running but not showing really isn’t a good use of time for anyone.

Especially when it is still the same error message and that has been answered!

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 31, 2024, 8:46am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/18 "2024-07-31T08:46:51Z")

</div>

I have tried many time wrapping those input variables with `Vector()` and `collect()` but still getting same Tuple error. These input variables are defined as:

```julia
    theta_grid_stream_coord = π .- atan.(x_grid_stream', -z_grid_stream')
    theta_grid_stream_pix = ((theta_grid_stream_coord .+ theta[1]) ./ (2.0 * π .+ 2.0 * theta[1])) .* (2 * ntheta + 1)

    r_grid_stream_pix = similar(r_grid_stream_coord)
    for (i, j) in Tuple.(CartesianIndices(r_grid_stream_coord))
        r_val = r_grid_stream_coord[i, j]
        index = sum(r .< r_val) - 1
        if index < 1
            r_grid_stream_pix[i, j] = -1
        elseif index < nr - 1
            r_grid_stream_pix[i, j] = index + (r_val - r[index]) / (r[index + 1] - r[index])
        else
            r_grid_stream_pix[i, j] = nr
        end
    end

```

Please tell where is problem?

---

<div class="post-metadata">

**Author:** ![kellertuer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kellertuer/32/220707_2.png) [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Post date:** [July 31, 2024, 8:59am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/19 "2024-07-31T08:59:09Z")

</div>

You always only post snippets so I can only guess.

Those lines generate the two variables that **You put into a tuple when you call the function**. But I can only guess, since you never post reproducible running code – I think I can not help you, because I am only repeating the requests everyone else does on – please read the answers, please make a reasonable effort yourself, please post reproducible examples that we can run.

---

<div class="post-metadata">

**Author:** ![raman\_kumar](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raman_kumar/32/26782_2.png) [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Post date:** [July 31, 2024, 9:02am UTC](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/20 "2024-07-31T09:02:23Z")

</div>

Please see this [Python map\_coordinates() equivalent in Julia - #13 by raman\_kumar](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461/13) it contains everything.

[Next page](https://discourse.julialang.org/t/python-map-coordinates-equivalent-in-julia/117461.md?page=2)
