我一直在制作一个Numpy脚本,它突然开始表演了。 我在开头编写了For循环行,并且测试了大约20次左右的脚本没有任何问题。现在我认为其他问题已经解决,Python正在告诉我" for"语法错了。有人有什么想法吗? 确切的Python输出是:
File "Test.py", line 17
for t in range(10):
^
脚本代码是:
#!/Library/Frameworks/EPD64.framework/Versions/7.3
import numpy as np
import scipy as sp
tau = 10
c = sp.recfromtxt("test.txt")
binsmax = np.max(c)
f, dummy = np.histogram(c, bins=(np.arange(binsmax+1))
for t in range(tau):
if t==0:
a = c[:len(c)-1]
else:
a = c[:-(t+1)]
d = c[1:]
b = d
c = a + b
newmax = np.max(c)
if binsmax < newmax:
binsmax = newmax
hist, dummy2 = np.histogram(c, bins=[np.arange(binsmax+1)])
if binsmax < newmax:
difference = newmax - binsmax
np.append(f, np.zeros(difference))
else:
difference = binsmax - newmax
np.append(hist, np.zeros(difference))
e = f
f = hist + e # 'f' is the running histogram
sp.savetxt(str(t)+"c.txt", c)
sp.savetxt(str(t)+"f.txt", f)
谢谢!
答案 0 :(得分:5)
你在这一行中缩短了一小段时间:
f, dummy = np.histogram(c, bins=(np.arange(binsmax+1))