Python, interpolation,
<p>This issue realy drives me crazy. 
I have got ascii file with ~1 000 000 rows in it. 
There are 3 columns
X - coordinate, Z- depths- V -speed. For instance:</p>

<pre><code>         X            Z               V
      45000       -11657.8        5985.61
      45000      -11578.22       5974.688
      45000      -11259.92       5930.935
     287800      -1034.451       2062.341
     287800      -1014.557       2051.226
     287800      -934.9814       2006.724
</code></pre>

<p>I need interpolate Depth(Z)[-15 000 to 0] with Speed(V) by steps (For each 2000m or 100m etc)
For example </p>

<pre><code>       45000       -11657.8        5985.61
       45000       -11600          ??????
       45000       -11578.22       5974.688
       45000       -11500          ?????
       45000       -111034.451     2062.341
       287800      -934.9814       2006.724
       287800      -900            ????
       287800      -895.1937       1984.451
</code></pre>

<p>What I did:</p>

<pre><code>import numpy as np
from scipy.interpolate import interp1d

with open('my data' ,'r') as f:

header1 = f.readline()  ###skip the first head line  
X_list=[] #### Create 3 empty lists
Z_list=[]
V_list=[]
for line in f:
    line = line.strip()
    columns = line.split()
    X = (float(columns[0])) ### separete columns and add to list and convert 
    Z = (float(columns[1])) ###to float
    V = (float(columns[2]))
    X_list.append(X)
    Z_list.append(Z)
    V_list.append(V)
x = np.linspace(min(Z_list),max(Z_list),6) ## step 3000m = 6 parts
print (x)
</code></pre>

<p>result:</p>

<p>[-15000. -12000.  -9000.  -6000.  -3000.      0.]</p>

<p>Now I got:</p>

<pre><code>X             Z         V

45000       -15000    ??????
45000       -12000    ??????
45000       -9000     ??????
45000       -6000     ??????
45000       -3000     ??????
</code></pre>

<p>So the question is. How could I interpolate this speed to interesting   depths for each coordinates??
Thank you for any advice</p>

<p>In order to interpolate, you need some example of inputs and outputs that will be the base of the interpolation. In your case, <code>Z_list</code> is the input and <code>V_list</code>, the output.</p>

<p>Next, you can use the <code>interp</code> function from <a href="http://www.numpy.org/" rel="nofollow">numpy</a>, which expect an array to interpolate <code>x</code>, followed by the input <code>Z_list</code> and output <code>V_list</code>. Let's follow the example in <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.interp.html" rel="nofollow">its documentation</a>.</p>

<pre><code>import numpy as np
print np.interp(x, Z_list, V_list)
</code></pre>

python numpy interpolation