分形维数、盒数/激活盒矩阵元素的问题

2024-07-05 14:48:58 发布

您现在位置:Python中文网/ 问答频道 /正文

大家好,我做了一个算法来计算覆盖洛伦兹吸引子轨迹的盒子数。我得到这个错误:

 Boxmatrix[int(coordenada[0])][int(coordenada[1])] = 1
IndexError: index 1084 is out of bounds for axis 0 with size 1084

我不知道如果索引I没有参与boxmatrix行代码,为什么boxmatrix不会被1s覆盖。请帮忙,我做了很多评论来解释我的代码

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[:,0]), 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)

Tags: oftheinnumbercoordinatedatathatis