【发布时间】:2019-11-09 22:34:49
【问题描述】:
早上好!
我有一个 nxn 矩阵,其中 n 大到足以让我溢出。
我尝试用数学方法解决这个问题,它适用于小 n,但现在我从指数中得到溢出。
为了更好地解释这里的代码:
# create a quadratic Matrix matrix with shape 500x500
matrix = [[ 1.03796037 -0.00898546 -0.00410423 ... -0.0453022 0.02608995
-0.01146299]
...
[-0.01146299 -0.04572196 0.07370042 ... 0.03203931 0.07298667
0.98693473]]
# calculate the mean of matrix
mean = matrix.mean()
# calculate n
n = matrix.shape[0]
# divide the mean from the matrix and calculate the determinant
determinant = np.linalg.det(matrix/mean)
# use now det(c*M) = c^n*det(M)
solution = mean**n*determinant
>>>> inf
这种方法可以防止np.linalg.det() 函数溢出,但是计算mean**n 的幂会导致溢出,我不知道如何解决这个问题。平均值是浮点数和整数
你能在这里帮忙吗?请仅使用 Python 或 numpy。
【问题讨论】:
-
也许看看这篇关于如何处理大量数字的帖子 => softwareengineering.stackexchange.com/questions/128589/…
-
@VictorDeleau 你好维克多。我在创建这个问题之前看到了这个问题,因为我无法将那里的解决方案与我的问题联系起来。这里我们有一个 float ** large int。
标签: python python-3.x numpy matrix determinants