title: How to perform bilinear interpolation in Python
body: <p>I would like to perform blinear interpolation using python.<br>
  Example gps point for which I want to interpolate height is:<br></p>
  <pre><code>B = 54.4786674627
  L = 17.0470721369
  </code></pre>
  <p>using four adjacent points with known coordinates and height values:</p>
  <pre><code>n = [(54.5, 17.041667, 31.993), (54.5, 17.083333, 31.911), (54.458333, 17.041667, 31.945), (54.458333, 17.083333, 31.866)]
  </code></pre>
  <br>
  <pre><code>z01    z11
  
       z
  z00    z10
  </code></pre>
  <br>
  and here's my primitive attempt:
  <pre><code>import math
  z00 = n[0][2]
  z01 = n[1][2]
  z10 = n[2][2]
  z11 = n[3][2]
  c = 0.016667 #grid spacing
  x0 = 56 #latitude of origin of grid
  y0 = 13 #longitude of origin of grid
  i = math.floor((L-y0)/c)
  j = math.floor((B-x0)/c)
  t = (B - x0)/c - j
  z0 = (1-t)*z00 + t*z10
  z1 = (1-t)*z01 + t*z11
  s = (L-y0)/c - i
  z = (1-s)*z0 + s*z1
  </code></pre>
  <br>
  where z0 and z1<br>
  <pre><code>z01  z0  z11
  
       z
  z00  z1   z10
  </code></pre>
  <br>
  I get 31.964 but from other software I get 31.961.<br>
  Is my script correct?<br>
  Can You provide another approach?
  <p><br><br>
  <strong>2022 Edit:</strong><br>
  I would like to thank everyone who, even more than a decade after publication of this question, gives new answers to it.</p>