Python 当数据较大时,构造一个适合拉普拉斯分布的数组

Python 当数据较大时,构造一个适合拉普拉斯分布的数组,python,Python,我有一个问题,当我想建立一个数组,以适应它的拉普拉斯分布。我的想法是,我有一张360x180像素的图像中的像素强度数据,它有一个很大的赤道偏差(见下图),我想看看它的拉普拉斯曲线。我的想法是逐行检查每个像素,如果它的强度大于一个常数,我会在我的“拉普拉斯数组”(将要拟合的数组)中添加像那一行那样的像素数。这并不十分清楚,因此我使用了以下代码: # For H=180, goes from -90 to 89 (to have 180 values) heights = np.linspace(n

我有一个问题,当我想建立一个数组,以适应它的拉普拉斯分布。我的想法是,我有一张360x180像素的图像中的像素强度数据,它有一个很大的赤道偏差(见下图),我想看看它的拉普拉斯曲线。我的想法是逐行检查每个像素,如果它的强度大于一个常数,我会在我的“拉普拉斯数组”(将要拟合的数组)中添加像那一行那样的像素数。这并不十分清楚,因此我使用了以下代码:

# For H=180, goes from -90 to 89 (to have 180 values)
heights = np.linspace(np.ceil(-H / 2), np.floor(H / 2), H + 1 if H % 2 == 0 else H)[:-1] 

lapl_arr = np.empty(0) # The "laplacian array"
points = data.copy()
epsilon = np.amax(data) / 10 # The constant which will be the threshold for the intensity

# For each row
for i in range(H):
    count = 1
    # Counts the number of pixels that have a greater "intensity" than epsilon
    for x in points[i]:
        if x >= epsilon:
            count += 1

    # Append the actual height 'count' times, to be able to fit a Laplacian distribution on it
    for val in range(count):
        lapl_arr = np.append(lapl_arr, heights[i])
它计算“拉普拉斯数组”。例如,它将类似于

lapl_arr
>>> [-90. -89. -88. -88. -88. ...  86.  86.  86.  87.  87.  88.  89.]
然后,为了适应它,简单地说:

# Fit the laplacian distribution
lin = np.linspace(min(lapl_arr), max(lapl_arr), len(lapl_arr))
mu, beta = laplace.fit(lapl_arr)
pdf_lapl = laplace.pdf(lin, mu, beta)
这实际上效果很好,如下图所示。现在,我的问题来了,当我想把拉普拉斯分布拟合到这一过程的结果上,大约100幅这样的图像,来查看所有数据的全局偏差。由于每个图像都有一个略小于10000点的点,其强度大于ε,我们的拉普拉斯阵列将变得非常大。。。(也许它会起作用,但过程肯定会很长,而且占用的内存也太大了)

你有没有更好的办法来做这件事

图像: