Multiplication matricielle
La fonction Numpu matmul () est utilisée pour renvoyer le produit matriciel de 2 tableaux. Voici comment ça marche
1) tableaux 2-D, il renvoie le produit normal
2) Dimensions> 2, le produit est traité comme un empilement de matrice
3) Le tableau 1-D est d'abord promu en matrice, puis le produit est calculé
numpy.matmul(x, y, out=None)
Ici,
x, y : tableaux d'entrée. scalaires non autorisés
out : il s'agit d'un paramètre facultatif. Habituellement, la sortie est stockée dans ndarray
Exemple:
De la même manière, vous pouvez calculer la multiplication des matrices avec np.matmul
### Matmul: matruc product of two arraysh = [[1,2],[3,4]]i = [[5,6],[7,8]]### 1*5+2*7 = 19np.matmul(h, i)
Production:
array([[19, 22],[43, 50]])
Déterminant
Enfin, si vous avez besoin de calculer le déterminant, vous pouvez utiliser np.linalg.det (). Notez que numpy s'occupe de la dimension.
## Determinant 2*2 matrix### 5*8-7*6np.linalg.det(i)
Production:
-2.000000000000005