Created
January 7, 2018 11:28
-
-
Save J535D165/a2ac7f27ad6ddd6ee85e7d30e9f4080e to your computer and use it in GitHub Desktop.
crop and resize numpy array
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
from scipy import interpolate | |
def crop_and_resample_2darray(arr, x_crop, y_crop, resample, *args, **kwargs): | |
"""Crop a 2darray and resize the data""" | |
len_x_crop = x_crop[1]-x_crop[0] | |
len_y_crop = y_crop[1]-y_crop[0] | |
arr_crop = arr[x_crop[0]:x_crop[1], y_crop[0]:y_crop[1]] | |
f = interpolate.interp2d(np.arange(len_y_crop), | |
np.arange(len_x_crop), | |
arr_crop, | |
*args, **kwargs) | |
result = f(np.arange(len_x_crop, step=len_x_crop/resample[1]), | |
np.arange(len_y_crop, step=len_y_crop/resample[0])) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment