# Multidimensional data interpolation

**URL:** <https://discourse.julialang.org/t/multidimensional-data-interpolation/54859>\
**Category:** General Usage\
**Tags:** question, interpolations\
**Created:** [February 8, 2021, 6:41pm UTC](https://discourse.julialang.org/t/multidimensional-data-interpolation/54859 "2021-02-08T18:41:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![taeukseo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taeukseo/32/21819_2.png) [@taeukseo](https://discourse.julialang.org/u/taeukseo)\
**Post date:** [February 8, 2021, 6:41pm UTC](https://discourse.julialang.org/t/multidimensional-data-interpolation/54859/1 "2021-02-08T18:41:14Z")

</div>

I have been struggling to perform multidimensional interpolation using values. What I have at the moment are the following:

_A_: a vector of length _a_ .

_B_: a vector of length _b._

_C_: a vector of length _c_.

_V_ : realizations from an unknown function V, recorded in a 3-D array of size (a,b,c).

I hope to obtain interpolated values for _V2_ , with a much finer grid than A, B, and C.

I first tried to use Interpolations.jl but was unsuccessful. Any insights would be appreciated. Thanks!

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [February 8, 2021, 6:53pm UTC](https://discourse.julialang.org/t/multidimensional-data-interpolation/54859/2 "2021-02-08T18:53:01Z")

</div>

If your grid is uniformly-spaced, you can use [scaled bsplines](http://juliamath.github.io/Interpolations.jl/latest/control/#Scaled-BSplines-1), otherwise you’ll need to use [gridded interpolation](http://juliamath.github.io/Interpolations.jl/latest/control/#Gridded-interpolation-1). If the documentation isn’t enough to go on, can you provide a minimal working example with definitions of your vectors?

---

<div class="post-metadata">

**Author:** ![taeukseo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taeukseo/32/21819_2.png) [@taeukseo](https://discourse.julialang.org/u/taeukseo)\
**Post date:** [February 8, 2021, 7:06pm UTC](https://discourse.julialang.org/t/multidimensional-data-interpolation/54859/3 "2021-02-08T19:06:09Z")

</div>

Hi, in my example here, the grids are irregular and defined in a separate function. They are discretized values from random variables and hence difficult to parameterize. I was wondering if there are any ways to interpolate just using these vector elements?

```julia
julia> A
11-element Array{Float64,1}:
  0.1
  0.158
  0.251
  0.398
  0.631
  1.0
  1.585
  2.512
  3.981
  6.31
 10.0

julia> B
5-element Array{Float64,1}:
 -5.729
 -5.716
 -5.704
 -5.691
 -5.678

julia> C
5-element Array{Float64,1}:
 -0.823
 -0.411
  0.0
  0.411
  0.823

```

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [February 8, 2021, 7:16pm UTC](https://discourse.julialang.org/t/multidimensional-data-interpolation/54859/4 "2021-02-08T19:16:49Z")

</div>

```julia
julia> itp = interpolate((A, B, C), V, Gridded(Linear()));

julia> itp(1, -5.7, 0)
0.35565970118183643

```

---

<div class="post-metadata">

**Author:** ![taeukseo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/taeukseo/32/21819_2.png) [@taeukseo](https://discourse.julialang.org/u/taeukseo)\
**Post date:** [February 8, 2021, 8:22pm UTC](https://discourse.julialang.org/t/multidimensional-data-interpolation/54859/5 "2021-02-08T20:22:53Z")

</div>

Thanks so much! That worked very well for the example above.

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [February 8, 2021, 11:01pm UTC](https://discourse.julialang.org/t/multidimensional-data-interpolation/54859/6 "2021-02-08T23:01:19Z")

</div>

I’m a little puzzled. From the posted example:

```julia
A = [0.1,0.158,0.251,0.398,0.631,1.0,1.585,2.512,3.981,6.31,10.0]
B = [-5.729, -5.716, -5.704, -5.691, -5.678]
C = [-0.823, -0.411, 0.0, 0.411, 0.823]

```

But…  
a. `V` is not defined in the solution,  
b. The call to `itp` is given as `itp[1,-5.7,0]`, although I would have guessed from the documentation of `Interpolations` that it should have been `itp(1,-5.7,0)`??

One obvious use of interpolation is with thermodynamics tables, where some data are often missing. Can `Interpolations` be used for such data, or are there other packages? Example [sorry for the “big” example – missing data are in the last column]:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/b/bb2e77d2e04f3830a00e06dbadcfbb5cffba53ee.png)

---

<div class="post-metadata">

**Author:** ![stillyslalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stillyslalom/32/45687_2.png) [@stillyslalom](https://discourse.julialang.org/u/stillyslalom)\
**Post date:** [February 8, 2021, 11:48pm UTC](https://discourse.julialang.org/t/multidimensional-data-interpolation/54859/7 "2021-02-08T23:48:41Z")

</div>

a) I just created a dummy `V = rand(11, 5, 5)`.  
b) Yeah, you’re right - the bracket syntax still works, but has been deprecated for a while.

Interpolations.jl isn’t ideally suited to fill in missing values - [Impute.jl](https://invenia.github.io/Impute.jl/latest/api/imputors/#Interpolate) should do the trick.
