python - Implement rms without numpy -
i have implement function calculate rms without using numpy, using data in txt. have following:
import numpy np import matplotlib.pyplot plt import math def main(): # cargando los datos avrgpress = [] press = [] open("c:\users\saulo\downloads\prvspy.txt","r") a: x in a: columnas = x.split('\t') avrgpress.append(float(columnas[0])) press.append(float(columnas[1])) def error(avrgpress, press): lista3 = [0]*len(lista) x in xrange(len(lista)): lista3[x] = lista3[x] * sum(sqrt(float(1.0/1064) * (avrgpress - press)**2)) return lista3 if __name__ == '__main__': main()
when building, not out rms. suggestions or solution?
is want, rms( avrgpress )
?
from __future__ import division # necessary import math def rms( alist ): """ rms( [1, 2, 3] ) = sqrt( average( 1**2 + 2**2 + 3**2 )) = 2.16 """ sum_squares = sum([ x**2 x in alist ]) return math.sqrt( sum_squares / len(alist) ) ... print rms( [1, 2, 3] )
Comments
Post a Comment