程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Matrix vector multiplication in Python numpy (np.multiply(), np dot()、np. Matmul() and asterisks (*), @)

編輯:Python

python Numpy Matrix vector multiplication in

  • summary
  • 1. about np.array object
    • 1.1 Element multiplication use a*b or np.multiply(a,b)
    • 1.2 Matrix multiplication use np.dot(a,b) or np.matmul(a,b) or a.dot(b) or [email protected]
  • 2. about np.matrix object
    • 2.1 Element multiplication use np.multiply(a,b)
    • 2.2 Matrix multiplication use a*b or np.dot(a,b) or np.matmul(a,b) or a.dot(b)

summary

  • Element multiplication :np.multiply(a,b)
  • Matrix multiplication :np.dot(a,b) or np.matmul(a,b) or a.dot(b) Or directly a @ b

Only pay attention *, stay np.array Element multiplication is overloaded in , stay np.matrix Matrix multiplication is overloaded in !

Be careful :
about Array Formatted data , A one-dimensional 、 Two dimensional arrays can use elements 、 matrix multiplication ;
about matrix Formatted data , One dimensional matrix can only be multiplied by elements , Two dimensional matrices are OK .

1. about np.array object

Two dimensional array

One dimensional array

1.1 Element multiplication use a*b or np.multiply(a,b)

Two dimensional array

One dimensional array

1.2 Matrix multiplication use np.dot(a,b) or np.matmul(a,b) or a.dot(b) or [email protected]

Two dimensional array

One dimensional array ( Multiply the corresponding positions , And then sum up )

2. about np.matrix object

Two dimensional matrix

One dimensional matrix

2.1 Element multiplication use np.multiply(a,b)

Two dimensional matrix

One dimensional matrix

2.2 Matrix multiplication use a*b or np.dot(a,b) or np.matmul(a,b) or a.dot(b)

Two dimensional matrix

One dimensional matrix ( Report errors , Matrix operations cannot be performed directly )

Reference resources :
Numpy Matrix vector multiplication in
python in np.multiply()、np.dot() And asterisk (*) The difference between the three multiplication operations


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved