如何有效地将数据保存到文件(我将在稍后绘制)?
我从我的研究中得到了这个:
#Open new data file
f = open("data2.txt", "w")
f.write( str(yEst) ) # str() converts to string
f.close()
Run Code Online (Sandbox Code Playgroud)
到目前为止,这是我的一些代码:
for i in drange2(0, 2*math.pi + 0.0634665182543392 , 0.0634665182543392):
for x in range(1,N+1):
yEst = yEst + a * cos(x* i)
#print yEst
f.write( str(yEst) ) # str() converts to string
yEst=0
f.close()
Run Code Online (Sandbox Code Playgroud)
现在,当我打开我的文件" data2.txt"时,我无法读取数据,因为它没有"有条理".我怎样才能使用下一行,f.write( str(yEst) )以便我有一个包含我的'yEst'数据的列到文件"data2.txt?感谢您提前考虑:)
PS:yEst看起来像(在data2.txt文件中):48.901347147148.605785828748.114506165947.429486 ..我希望它作为一个列: - >
48.9013471471 (new line)
48.6057858287 (new line)
48.1145061659 (new line)
47.4294863684
etc ..
Run Code Online (Sandbox Code Playgroud) 我想知道如何在 python 中表示总和而不需要像这里这样的循环
我们有:
def rosen(x):
"""The Rosenbrock function"""
return sum(100.0*(x[1:]-x[:-1]**2.0)**2.0 + (1-x[:-1])**2.0)
Run Code Online (Sandbox Code Playgroud)
我的功能如下:V(theta) = Sum(i=1->N)[a0*(cos(i*theta)]
预先感谢您的帮助 :):)