np.dot usage

Creative Commons License Copyright: Attribution, allow others to create paper-based, and must distribute paper (based on the original license agreement with the same license Creative Commons )
  • For vector:

in . d O t ( v ) = in v c O s i u.dot(v)=|u|*|v|*cos \theta
point value by seeking out a
* corresponds to multiplication by multiplying each element
may benp.dot(u,v), it may be written asu.dot(v)

Caution: the * operator will perform an elementwise multiplication, NOT a dot product:

  • For matrix:

A.dot(B), Denotes the matrix multiplication, a matrix is ​​obtained. (Row vector A m × n m×n column vector of B and n × k n×k , respectively, do dot dot, end up with a matrix m × k m×k . )
A*BRepresents a multiplication element,

Caution: NumPy’s * operator performs elementwise multiplication, NOT a matrix multiplication

Point multiply and multiply * the meaning and role of unity.

  • * Take boardcasting trigger mechanism of python

import numpy as np
a = np.array([1,2,3])
b = np.array([2])
print(a*b)

[2 4 6]

 c = np.array([1,2,3,4])
 print(a*c)


 Traceback (most recent call last):File "<stdin>", line 1, in <module>ValueError: operands could not be broadcast together with shapes (3,) (4,)

Guess you like

Origin blog.csdn.net/houhuipeng/article/details/93600950