初学Python,array 和 Matrix 的相乘,被结果弄蒙了。
>>> x = np.array( ((2,3), (3, 5)) )
>>> y = np.array( ((1,2), (5, -1)) )
>>> x * y
array([[ 2, 6],
[15, -5]])
>>> x = np.matrix( ((2,3), (3, 5)) )
>>> y = np.matrix( ((1,2), (5, -1)) )
>>> x * y
matrix([[17, 1],
[28, 1]])
>>> np.dot(x,y)
matrix([[17, 1],
[28, 1]])
(2,3)
(3, 5)
(1,2)
(5, -1))
matrix([[17, 1],
[28, 1]])
比价了一下结果,array的相乘,比较好理解,也比较直观;Matrix 的就稍微复杂一点,详见下:
[[2, 3], [[1, 2], [[2 * 1, 3 * 2],
[3, 5]] x [5, -1]] = [3 * 5, 5 * -1]]
and the other is matrix multiplication [19]:
[[2, 3], [[1, 2], [[2 * 1 + 3 * 5, 2 * 2 + 3 * -1],
[3, 5]] x [5, -1]] = [3 * 1 + 5 * 5, 3 * 2 + 5 * -1]]
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/6126/viewspace-2766089/ ,如需转载,请注明出处,否则将追究法律责任。