Created
November 24, 2015 00:00
-
-
Save fjarri/b6f1faefa95995d119b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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