繁体   English   中英

为什么我不断收到此错误消息; IndexError:索引 100 超出尺寸为 100 的轴 0 的范围

[英]Why do I keep getting this error message; IndexError: index 100 is out of bounds for axis 0 with size 100

这是导致问题的代码片段:

import numpy as np
import matplotlib.pyplot as plt

x = 100

a_1 = np.arange(start=0,stop=(1/15)**(1/3)+0.0001,step=0.0001)
b_1 = np.empty((len(a_1),x),dtype=object)
g4 = np.empty((len(a_1),x))
g6 = np.empty((len(a_1),x))
g4min = np.empty((1,len(a_1)))
g6min = np.empty((1,len(a_1)))
g4max = np.empty((1,len(a_1)))
g6max = np.empty((1,len(a_1)))
b1 = np.empty((1,len(a_1)))

np.seterr(divide='ignore', invalid='ignore')

diter = 1/x

iter = np.arange(0, x, diter)

for n in range(0,len(a_1)+1):
     b1[n] = (-8*a_1[n]**3+1+(96*a_1[n]**6-16*a_1[n]**3+1)**(1/2))**(1/3)/(2**(1/3))-a_1[n]-     (2*(2)**(1/3)*a_1[n]**2)/(-8*a_1[n]**3+1+(96*a_1[n]**6-16*a_1[n]**3+1)**(1/2))**(1/3)/x
     h = 0
     for j in range(0,len(iter)+1):
        b_1[n][j] = b1[n]*h
        h = h+1

我知道我为 b_1 和 b1 定义 for 循环的方式存在问题,但我似乎找不到它。 谢谢。

Python arrays 从 0 开始到长度 -1 结束。 您的数组有 100 个元素,因此最后一个索引为 99。对于 101 的数组,最后一个索引为 100。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM