Python中(大)1554 x 1554矩阵的行列式 [英] Determinant of a (large) 1554 x 1554 matrix in Python
问题描述
我需要在python中以单精度计算大的1554、1554值矩阵的行列式.这样做时,我会遇到运行时警告:
I need to calculate the determinant of a large 1554,1554 matrix of values with single precision in python. In doing so I encounter a runtime warning:
import numpy as np
from numpy import linalg as LA
a = np.random.random((1554, 1554))
b = np.random.random((1554, 1554))
c = np.dot(a,b)
det = LA.det(c)
RuntimeWarning:在det中遇到溢出 r = _umath_linalg.det(a,signature = signature)
RuntimeWarning: overflow encountered in det r = _umath_linalg.det(a, signature=signature)
关于如何解决此问题的任何想法?非常感谢!
Any ideas on how I can work around this problem? Many thanks!
这个问题的独特之处在于,它专门涉及以双精度计算大型矩阵的行列式,尽管此处包括一个可能的答案:
this question is unique in that it specifically refers to computing the determinant of large matrix in double precision, though a possible answer is included here: Can I get the matrix determinant using Numpy?
推荐答案
您可以使用以下关系: https://wikimedia.org/api/rest_v1/media/math/render/svg/f6404a766d86e9d78a5c4f82e05de37469a5f8e9
You can use this relation: https://wikimedia.org/api/rest_v1/media/math/render/svg/f6404a766d86e9d78a5c4f82e05de37469a5f8e9
来自 https://en.wikipedia.org/wiki/Determinant#Properties_of_the_determinant
因此,将矩阵除以平均值,然后计算行列式以避免溢出.以后,您可以将均值乘以n(一轴的长度)的幂次
So divide your matrix by the mean and then compute the determinant to avoid overflow. Later you can multiply with the mean to the power of n (length of one axis)
我不确定平均值是否是理想选择.这更多是一个数学问题
edit: I'm not sure if the mean is the ideal choice though. This is more a math question
这篇关于Python中(大)1554 x 1554矩阵的行列式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!