Use scipy.interpolate.interp2d
:
Interpolate over a 2-D grid.
x, y and z are arrays of values used to approximate some function f: z = f(x, y) which returns a scalar value z. This class returns a function whose call method uses spline interpolation to find the value of new points.
So you have an array orig
that you want to generate 100x50 array res
using bicubic interpolation
# Adapted from https://stackoverflow.com/a/58126099/17595968
from scipy import interpolate as interp
import numpy as np
orig = np.random.randint(0, 100, 25).reshape((5, 5))
W, H = orig.shape
new_W, new_H = (100, 50)
map_range = lambda x: np.linspace(0, 1, x)
f = interp.interp2d(map_range(W), map_range(H), orig, kind="cubic")
res = f(range(new_W), range(new_H))
Edit:
If what you want is coordinates of 100x50 grid in 5x5 grid you can use numpy.meshgrid
:
#From https://stackoverflow.com/a/32208788/17595968
import numpy as np
W, H = 5, 5
new_W, new_H = 100, 50
x_step = W / new_W
y_step = H / new_H
xy = np.mgrid[0:H:y_step, 0:W:x_step].reshape(2, -1).T
xy = xy.reshape(new_H, new_W, 2)
xy