本来以为这辈子都和数学没啥关系了,结果遇到了np.dot()。
numpy中的“*”和“dot”运算是完全不同的,前者是直接计算,后者是矩阵相乘。
(venv) [root@localhost tf]# python Python 3.4.5 (default, May 29 2017, 15:17:55) [GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import numpy as np >>> a = np.array([[1,2],[3,4]]) >>> b = np.array([[1,2],[3,4]]) >>> c = a * b >>> c array([[ 1, 4], [ 9, 16]]) >>> d = np.dot(a, b) >>> d array([[ 7, 10], [15, 22]])
矩阵相乘:
例子: