小编Den*_*nis的帖子

对于大小为 100 的轴 0,索引 100 超出范围

我试图用 python 编写一个程序来计算无穷级数

1/1^2 + 1/2^2 + 1/3^2 +1/4^2 +.....

我的代码如下:

n = 100
x = np.zeros([n])
x[0] = 0
for i in range(n):
   x[i+1] = x[i] + 1/float((i+1)**2)
print x[99]
Run Code Online (Sandbox Code Playgroud)

当我尝试执行代码时,它返回如下内容:

索引错误:索引 100 超出轴 0 的范围,大小为 100

我想知道代码有什么问题。谢谢!:)

python compiler-errors

2
推荐指数
1
解决办法
8128
查看次数

标签 统计

compiler-errors ×1

python ×1