Created
June 27, 2023 14:42
-
-
Save Humboldt-Penguin/fcbf1d965be8c62f33495de90b8cb6f9 to your computer and use it in GitHub Desktop.
supplement to stackoverflow comment on this post: https://stackoverflow.com/questions/75427538/regulargridinterpolator-excruciatingly-slower-than-interp2d
This file contains hidden or 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
# supplement to my stackoverflow comment on this post: https://stackoverflow.com/questions/75427538/regulargridinterpolator-excruciatingly-slower-than-interp2d | |
# since `x_vals` and `y_vals` are decreasing rather than increasing, we do some trickery on top of `np.searchsorted()` to get the desired indices. | |
i_x = x_vals.shape[0] - np.searchsorted(np.flip(x_vals), x) | |
i_y = y_vals.shape[0] - np.searchsorted(np.flip(y_vals), y) | |
'''here's an option with list comprehension | |
points = [ | |
( | |
x_vals[i_x-1+i], | |
y_vals[i_y-1+j], | |
z_grid[i_x-1+i, i_y-1+j] | |
) | |
for i, j in [(i, j) for i in range(2) for j in range(2)] | |
] | |
''' | |
points = ( | |
( | |
x_vals[i_x - 1], | |
y_vals[i_y - 1], | |
z_grid[i_x - 1, i_y - 1] | |
), | |
( | |
x_vals[i_x], | |
y_vals[i_y - 1], | |
z_grid[i_x, i_y - 1] | |
), | |
( | |
x_vals[i_x - 1], | |
y_vals[i_y], | |
z_grid[i_x - 1, i_y] | |
), | |
( | |
x_vals[i_x], | |
y_vals[i_y], | |
z_grid[i_x, i_y] | |
) | |
) | |
return bilinear_interpolation(x, y, points) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment