A = numpy.matrix([[36, 34, 26],
[18, 44, 1],
[11, 31, 41]])
X1 = numpy.matrix([[46231154], [26619349], [37498603]])
需要将矩阵乘以向量。我试过了:
>>>A*X1
matrix([[ -750624208],
[ 2040910731],
[-1423782060]])
>>> numpy.dot(A,X1)
matrix([[ -750624208],
[ 2040910731],
[-1423782060]])
为什么是负数?没有更低的数字,例如:
A = numpy.matrix([[36, 34, 26],
[18, 44, 1],
[11, 31, 41]])
X1 = numpy.matrix([[8], [6], [6]])
>>>A*X1
matrix([[58],
[38],
[40]])
答案 0 :(得分:4)
我相信您使用的是32位系统,并且您看到整数溢出。尝试使用关键字参数dtype=np.int64
定义矩阵和向量,看看你是否得到了更有意义的答案。
在我的64位机器上,我有以下输出
In [1]: import numpy
In [2]: A = numpy.matrix([[36, 34, 26],
...: [18, 44, 1],
...: [11, 31, 41]])
In [3]:
In [3]: X1 = numpy.matrix([[46231154], [26619349], [37498603]])
In [4]: A*X1
Out[4]:
matrix([[3544343088],
[2040910731],
[2871185236]])