您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

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

5b51 2022/1/14 8:25:21 python 字数 1616 阅读 828 来源 www.jb51.cc/python

向量点乘(dot)和对应分量相乘?(multiply)?: >>>a array([1,2,3]) >>>b array([1.,1.,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
>> c
matrix([[1,3]])
>>> d
matrix([[ 1.,1.]])
>>> np.multiply(c,d)
matrix([[ 1.,3.]])
>>> np.dot(c,d)
Traceback (most recent call last):
  File "
  
   ",line 1,in 
   
    
ValueError: shapes (1,3) and (1,3) not aligned: 3 (dim 1) != 1 (dim 0)
   
  


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

>> a*b
array([ 1.,3.])
>>> c*d
Traceback (most recent call last):
  File "
  
   ",in 
   
    
  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) not aligned: 3 (dim 1) != 1 (dim 0)
   
  

总结

以上是编程之家为你收集整理的【Python】python中的乘法dot和对应分量相乘multiply全部内容,希望文章能够帮你解决【Python】python中的乘法dot和对应分量相乘multiply所遇到的程序开发问题。


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶