我必须使用txt中的数据来实现一个函数来计算rms而不使用numpy。我有以下内容:
import numpy as np
import matplotlib.pyplot as plt
import math
def main():
# Cargando los datos
avrgPress = []
press = []
with open("C:\Users\SAULO\Downloads\prvspy.txt","r") as a:
for 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)
for x in xrange(len(lista)):
lista3[x] = lista3[x] * sum(sqrt(float(1.0/1064) * (avrgPress - press)**2))
return lista3
if __name__ == '__main__':
main()
当你建造时,而不是rms。有什么建议或解决方案吗?
答案 0 :(得分:1)
这是你想要的,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 for x in alist ])
return math.sqrt( sum_squares / len(alist) )
...
print rms( [1, 2, 3] )