Skip to content

Instantly share code, notes, and snippets.

@fjarri
Created November 24, 2015 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fjarri/b6f1faefa95995d119b8 to your computer and use it in GitHub Desktop.
Save fjarri/b6f1faefa95995d119b8 to your computer and use it in GitHub Desktop.
import time
import numpy as np
from scipy.interpolate import griddata
def func(x, y):
return x*(1-x)*np.cos(4*np.pi*x) * np.sin(4*np.pi*y**2)**2
grid_x, grid_y = np.mgrid[0:1:200j, 0:1:200j]
points = np.random.rand(410500, 2)
values = func(points[:,0], points[:,1])
t1 = time.time()
grid_z1 = griddata(points, values, (grid_x, grid_y), method='linear')
print(time.time() - t1)
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
plt.subplot(121)
plt.imshow(func(grid_x, grid_y).T, extent=(0,1,0,1), origin='lower')
plt.plot(points[:,0], points[:,1], 'k.', ms=1)
plt.title('Original')
plt.subplot(122)
plt.imshow(grid_z1.T, extent=(0,1,0,1), origin='lower')
plt.title('Linear')
plt.savefig('t.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment