【Python】python中的乘法dot和对应分量相乘multiply

来源:互联网 发布:n9008v root软件 编辑:程序博客网 时间:2024/06/05 12:40

向量点乘 (dot) 和对应分量相乘 (multiply) :

>>> aarray([1, 2, 3])>>> barray([ 1.,  1.,  1.])>>> np.multiply(a,b)array([ 1.,  2.,  3.])>>> np.dot(a,b)6.0

矩阵乘法 (dot) 和对应分量相乘 (multiply) :
>>> cmatrix([[1, 2, 3]])>>> dmatrix([[ 1.,  1.,  1.]])>>> np.multiply(c,d)matrix([[ 1.,  2.,  3.]])>>> np.dot(c,d)Traceback (most recent call last):  File "<stdin>", line 1, in <module>ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)


写代码过程中,*表示对应分量相乘 (multiply) :

>>> a*barray([ 1.,  2.,  3.])>>> c*dTraceback (most recent call last):  File "<stdin>", line 1, in <module>  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\matrixlib\defmatrix.py", line 343, in __mul__    return N.dot(self, asmatrix(other))ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)

原创粉丝点击