Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resize array and fill with interpolation [closed]

This should be similar to image resealing, suppose having this vector,

x = np.array([10,50,40,20])

I need to scale it up to size 10, and fill the missing values using interpolation.

Any numpy or scipy function that does this?

like image 689
innuendo Avatar asked Dec 31 '25 07:12

innuendo


1 Answers

One way is using scipy.ndimage.interpolation.zoom. This will be zooming using spline interpolation. In order to use it you need to provide a zooming factor which in this case, given that you want an array of size 10, it should be 10/len(x):

from scipy.ndimage import interpolation

x = np.array([10,50,40,20])
i = 10
z = i / len(x)
# 2.5

x_int = interpolation.zoom(x,z)

Output

array([10, 18, 35, 50, 54, 49, 40, 30, 23, 20])
like image 177
yatu Avatar answered Jan 04 '26 12:01

yatu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!