微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

分形维数,框计数 Python/激活框矩阵元素的问题

如何解决分形维数,框计数 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 不会被 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 举报,一经查实,本站将立刻删除。