# Regridding 3d array

**URL:** https://discourse.julialang.org/t/regridding-3d-array/37349
**Category:** Data
**Created:** [April 10, 2020, 3:38pm UTC](https://discourse.julialang.org/t/regridding-3d-array/37349 "2020-04-10T15:38:27Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![asb](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@asb](https://discourse.julialang.org/u/asb)
#### Post date: [April 10, 2020, 3:38pm UTC](https://discourse.julialang.org/t/regridding-3d-array/37349/1 "2020-04-10T15:38:27Z")

</div>

nub question.  
I have a 3d array of input data1 of dimensions [nx,ny,nz]  
The data represent a 3D continuous function sampled on an irregular grid.  
data[i,j,k] is the data at grid point [i,j,k].  
xgrid1[i,j,k] are the x-coordinates of point [i,j,k].  
ygrid1[i,j,k] are the y-coordinates of point [i,j,k].  
zgrid1[i,j,k] are the z-coordinates of point [i,j,k].  
xgrid1, ygrid1, and zgrid1 could be instead be represented by an array of triple grid1.

xgrid2, ygrid2, and zgrid2 (or grid2) are the coordinates of a different grid.  
How do generate a 3D array data2 that approximates the function represented by data1 at the grid points defined by grid2?

This should be a trivial application of any interpolation package, but I find the documentation of the packages too concise to be of much help.

---

<div class="post-metadata">

### Author: ![AndiMD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/andimd/32/6531_2.png) [@AndiMD](https://discourse.julialang.org/u/AndiMD)
#### Post date: [April 10, 2020, 5:37pm UTC](https://discourse.julialang.org/t/regridding-3d-array/37349/2 "2020-04-10T17:37:32Z")

</div>

Hi asb,  
The Interpolations.jl package does linear interpolation on irregular grids, e.g. this:

```julia
using Interpolations

xg1,yg1,zg1 = sort(rand(50)),sort(rand(60)),sort(rand(70))
data1 = [sum(xyz) for xyz=Iterators.product(xg1,yg1,zg1)]

itp = interpolate((xg1,yg1,zg1), data1, Gridded(Linear()))
etpf = extrapolate(itp, Flat())

xg2,yg2,zg2 = range(0,1,length=10),range(0,1,length=11),range(0,1,length=12)
coords = Iterators.product(xg2,yg2,zg2)
data2 = (c->etpf(c...)).(coords)

```
