Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double the length of a python numpy array with interpolated new values

I have an array of 5 numbers:

A = [10, 20, 40, 80, 110]

I need to create a new array with a 10nth length numbers.

The extra numbers could be the average number between the two # of A.

for example: EDIT B = [10 , 15 , 20 ,30, 40, 60, 80, 95, 110 ]

Is it possible using a scipy or numpy function ?

like image 919
user1640255 Avatar asked May 05 '13 19:05

user1640255


1 Answers

Use numpy.interp:

import numpy as np
Y = [10, 20, 40, 80, 110]
N = len(Y)
X = np.arange(0, 2*N, 2)
X_new = np.arange(2*N-1)       # Where you want to interpolate
Y_new = np.interp(X_new, X, Y) 
print(Y_new)

yields

[  10.   15.   20.   30.   40.   60.   80.   95.  110.]

like image 132
unutbu Avatar answered Oct 12 '22 23:10

unutbu