我在做一些线性代数的事情,只是不知道为什么numpy
提供以下内容:
我从Mathematica得到的结果是
编辑*如果需要矩阵:
test = [[19722145, -21016468, 51417377],
[-185674670, 298847128, -428429486],
[289326728, -516012704, 691212936]]
A = [[9, 4, 1], [2, 0, 8], [-8, 8, -8]]
发布于 2018-06-19 12:33:38
正如@PaulPanzer所指出的,需要使用np.int64
D型数组。NumPy用途np.int32
对于平台/系统Configuration_1上的输入数组,不检查整数溢出。
然而,矩阵乘法的结果包括太大而不能存储在np.int32
。
因为NumPy不会自动将输入数组向上转换为np.int64
,需要指定np.int64
显式地,在定义数组或通过上播时:
import numpy as np
test = np.array([[19722145, -21016468, 51417377],
[-185674670, 298847128, -428429486],
[289326728, -516012704, 691212936]],
dtype=np.int64)
A = np.array([[9, 4, 1],
[2, 0, 8],
[-8, 8, -8]],
dtype=np.int64)
res = np.dot(test, A)
print(res)
[[ -275872647 490227596 -559748615]
[ 2354058114 -4170134568 5632538242]
[-3957788344 6687010400 -9368478392]]
https://stackoverflow.com/questions/-100005413
复制相似问题