-1

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

谢谢!

4

1 回答 1

5

您在这一行中缺少一个紧密的括号:

f, dummy = np.histogram(c, bins=(np.arange(binsmax+1))
于 2012-09-04T22:51:30.607 回答