Python 为什么我总是收到这个错误消息;索引器:索引100超出大小为100的轴0的界限

Python 为什么我总是收到这个错误消息;索引器:索引100超出大小为100的轴0的界限,python,Python,这是导致问题的代码片段: 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.empt

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

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数组从0开始,以长度-1结束。数组有100个元素,因此最后一个索引是99。对于101的数组,最后一个索引应该是100。

使用这个:对于范围内的n(len(a_1))数组索引从0开始。因此,长度为100的数组的有效索引为0到99。索引100超出范围。这可能不正确:
范围(0,len(iter)+1)
。感谢您的评论。我以前尝试过所有这些,但仍然得到相同的错误代码。