It is well known that IDW(Inverse Distance Weighted Interpolation) will not yield exactly the same value if we use the known locations as the input. Write a Python program to test
this property.
The following is a Python implementation of IDW. This function takes two input variables. Z is a list of lists where each element list contains four values: X, Y, Value, and Distance to target point. Z can also be a NumPy 2-D array. Variable b is the power of distance. It returns the estimated value at the target location. Note that we don't need to specify the target location per se. Instead in Z we have the distance from each known location to the target point.
def IDW(Z, b):
zw = 0.0 # sum of weighted z
sw = 0.0 # sum of weights
N = len(Z) # number of points in the data
for i in range(N):
d = Z[i][3]
if d == 0:
return Z[i][2]
w = 1.0/d**b
sw += w
zw += w*Z[i][2]
return zw/sw