早上好!
我有一个 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
Run Code Online (Sandbox Code Playgroud)
这种方法可以防止np.linalg.det()函数溢出,但是计算幂 …
有没有一种快速的方法来在python中创建具有1和x * 0的向量?
我想吃点东西
a = [1,0,0,0,0,0,0,0,0,...,0]
b = [1,1,0,0,0,0,0,0,0,...,0]
Run Code Online (Sandbox Code Playgroud)
我用列表尝试过,但看到你自己:(
list = [1, n*[0]]
list = np.array(list)
print(list)
==> [1 list([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])]
Run Code Online (Sandbox Code Playgroud)