Python中乘法dot与分量相乘multiply有何区别与联系?

2026-04-20 11:581阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计331个文字,预计阅读时间需要2分钟。

Python中乘法dot与分量相乘multiply有何区别与联系?

向量和矩阵乘法:

向量与矩阵相乘,使用点乘(dot)和对应分量相乘(multiply):aarray=[1, 2, 3]barray=[1., 1., 1.]result_dot=np.dot(aarray, barray)result_multiply=np.multiply(aarray, barray)

矩阵乘法:cmatrix=[[1, 2, 3]]dmatrix=[[1.]]

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

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

矩阵乘法 (dot) 和对应分量相乘 (multiply) :

>>> c matrix([[1, 2, 3]]) >>> d matrix([[ 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*b array([ 1., 2., 3.]) >>> c*d Traceback (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)

以上这篇对python中的乘法dot和对应分量相乘multiply详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

Python中乘法dot与分量相乘multiply有何区别与联系?

本文共计331个文字,预计阅读时间需要2分钟。

Python中乘法dot与分量相乘multiply有何区别与联系?

向量和矩阵乘法:

向量与矩阵相乘,使用点乘(dot)和对应分量相乘(multiply):aarray=[1, 2, 3]barray=[1., 1., 1.]result_dot=np.dot(aarray, barray)result_multiply=np.multiply(aarray, barray)

矩阵乘法:cmatrix=[[1, 2, 3]]dmatrix=[[1.]]

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

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

矩阵乘法 (dot) 和对应分量相乘 (multiply) :

>>> c matrix([[1, 2, 3]]) >>> d matrix([[ 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*b array([ 1., 2., 3.]) >>> c*d Traceback (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)

以上这篇对python中的乘法dot和对应分量相乘multiply详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持易盾网络。

Python中乘法dot与分量相乘multiply有何区别与联系?