numpy - Weighted smoothing of a 1D array - Python -


i quite new python , have array of parameter detections, of values detected incorrectly , (like 4555555):

array = [1, 20, 55, 33, 4555555, 1] 

and want somehow smooth it. right i'm doing weighted mean:

def smoothify(array):     in range(1, len(array) - 2):         array[i] = 0.7 * array[i] + 0.15 * (array[i - 1] + array[i + 1])     return array 

but works pretty bad, of course, can take weighted mean of more 3 elements, results in copypasting... tried find native functions that, failed.

could please me that?

p.s. sorry if it's noob question :(

thanks time, best regards, anna

would suggest numpy.average this. trick getting weights calculated - below zip 3 lists - 1 same original array, next 1 step ahead, next 1 step behind. once have weights, feed them np.average function

import numpy np array = [1, 20, 55, 33, 4555555, 1] arraycompare = zip(array, array[1:] + [0], [0] + array)  weights = [.7 * x + .15 * (y + z) x, y, z in arraycompare]  avg = np.average(array, weights=weights) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -