English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
In Python können wir verschiedene Matrixoperationen und Berechnungen lösen. Das Numpy-Modul bietet verschiedene Methoden für Matrixoperationen.
add() -Addiert die Elemente beider Matrizen.
Subtrahieren() -Subtrahiert die Elemente beider Matrizen.
split() -Teilt die Elemente beider Matrizen.
Multiplikation() -Multipliziert die Elemente beider Matrizen.
dot() -Es führt die Matrixmultiplikation aus,而不是 elementweises Multiplizieren.
sqrt() -Quadratwurzel von jedem Element der Matrix.
sum(x,axis) -Fügt alle Elemente der Matrix hinzu. Der zweite Parameter ist optional, wenn wir die Spaltensummen berechnen möchten, wobei axis 0 die Spaltensummen und axis1wird es verwendet, um die Zeilensummen zu berechnen.
„ T” -Führe die Transposition einer angegebenen Matrix aus.
import numpy # Zwei Matrizen werden durch Werte initialisiert x = numpy.array([1, 2], [4, 5]] y = numpy.array([7, 8], [9, 10]] # add() wird verwendet, um Matrizen zu addieren print("Addition von zwei Matrizen: ") print(numpy.add(x,y)) # subtract() wird verwendet, um Matrizen zu subtrahieren print("Subtraktion von zwei Matrizen: ") print(numpy.subtract(x,y)) # divide() wird verwendet, um Matrizen zu teilen print ("Matrix Division : ") print (numpy.divide(x,y)) print ("Multiplication of two matrices: ") print (numpy.multiply(x,y)) print ("The product of two matrices : ") print (numpy.dot(x,y)) print ("square root is : ") print (numpy.sqrt(x)) print ("The summation of elements : ") print (numpy.sum(y)) print ("The column wise summation : ") print (numpy.sum(y,axis=0)) print ("The row wise summation: ") print (numpy.sum(y,axis=1)) # using "T" to transpose the matrix print ("Matrix transposition : ") print (x.T)
输出结果
Addition of two matrices: [[ 8 10] [13 15]] Subtraction of two matrices : [[-6 -6] [-5 -5]] Matrix Division : [[0.14285714 0.25 ] [0.44444444 0.5 ]] Multiplication of two matrices: [[ 7 16] [36 50]] The product of two matrices : [[25 28] [73 82]] square root is : [[1. 1.41421356] [2. 2.23606798]] The summation of elements : 34 The column wise summation : [16 18] The row wise summation: [15 19] Matrix transposition : [[1 4] [2 5]]