Numpy坏了“For”循环?

2024-10-03 17:22:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在写一个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)

谢谢!你知道吗


Tags: inimporttxt脚本forifasnp