Home  >  Article  >  Java  >  How to express matrix vector multiplication in Java

How to express matrix vector multiplication in Java

WBOY
WBOYforward
2023-05-02 18:34:071458browse

Vector

Dot product
Formula: a ·b = |a| * |b| * cosθ The dot product is also called the inner product and quantity product of vectors. It is a The product of a vector and the length of its projection onto another vector; is a scalar quantity. The dot product reflects the "similarity" of two vectors. The more "similar" the two vectors are, the greater their dot product is.
How to express matrix vector multiplication in Java
Example: If vector a=(a1,b1,c1), vector b=(a2,b2,c2)
Vector a·Vector b=a1a2 b1b2 c1c2

Cross product
Formula: a × b = |a| * |b| * sinθ Cross product is also called the outer product and vector product of vectors. The result is a vector
Modulus length: |vector c|=|vector a×vector b|=|a||b|sin
Direction: The direction of the vector product of a vector and b vector is the same as this The two vectors are perpendicular to the plane and obey the right-hand rule.
Example
Vector a a2b1) (The main diagonal is positive)
(i, j, k are the unit vectors of the three mutually perpendicular coordinate axes in the space)

Matrix

Element multiplication: np .multiply(a,b)

Matrix multiplication: np.dot(a,b) or np.matmul(a,b) or a.dot(b) or directly use a @ b !

Only attention :*, overloaded in np.array for element multiplication, and in np.matrix for matrix multiplication!

Very good link

import numpy as np
a=np.array([[1,2],[3,4]])#生成数组矩阵b=np.array([[2,2],[1,3]])print(np.dot(a,b))>>[[ 4  8]
  [10 18]]

The above is the detailed content of How to express matrix vector multiplication in Java. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete