问题描述
大家好,我做了一个算法来计算覆盖洛伦兹吸引子轨迹的框数。我收到此错误:
Boxmatrix[int(coordenada[0])][int(coordenada[1])] = 1
IndexError: index 1084 is out of bounds for axis 0 with size 1084
如果索引 i 不参与 Boxmatrix 行代码,我不知道为什么 Boxmatrix 不会被 1 覆盖。请帮忙,我做了很多注释来解释我的代码
import numpy as np
#This program count the number of Boxes of lenght epsilon to cover the trajectory of the Lorenz attractor
#Lengt of the Box
epsilon = 0.05
#This is the data for the lorenz atractor,is a matrix with 2 columns,the first column has the x coordinate values and the second column has the y coordinate values
data = np.genfromtxt('lorenz.dat',usecols=(0,2),delimiter=',') # Each column has 14,000 elements
#Here I define a matrix of 2 zeros that will have the values of the x coordinate and y coordinate of all the rows of the data matrix
rows = np.zeros(2)
#Here I define the maxs and mins arrays,that contains the max and min of each column
maximos = np.array([max(data[:,0]),max(data[:,1])])
minimos = np.array([min(data[:,min(data[:,1])])
# Now I define the dimension of a Boxmatrix,# a is the number of epsilons that fits in the x coordinate of the full trajectory of the atracttor
a = int(np.ceil((maximos[0] - minimos[0]) / epsilon))
# b is the number of epsilon that fits in the y coordinate of the full trajectory of the attractor
b = int(np.ceil((maximos[1] - minimos[1]) / epsilon))
Boxmatrix = np.zeros((a,b))
for i in range(14000):
rows = data[i,:] # I fill the rows matrix with the ith row of the data matrix,that is the (x,y) position of the ith point of the attractor
coordenada = np.zeros(2) # I define a matrix coordenada of two zeros
for j in range(2):
# coordenada[0] is the number of epsilon Boxes to reach the point in the x coordinate dictated by the rows matrix
# coordenada[1] is the number of epsilon Boxes to reach the point in the y coordinate dictated by the rows matrix
coordenada[j] = np.ceil((rows[j] - minimos[j]) / epsilon)
if coordenada[j] == 0:
coordenada[j] = 1
# coordenada[j] is at the same time the indexes of the elements of the Boxmatrix,I activate them to count it
Boxmatrix[int(coordenada[0])][int(coordenada[1])] = 1
# I count the number of Boxes
n = np.sum(Boxmatrix)
print(n)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)