Python Numpy.linalg.inv() - Inverse Matrix

Jinku Hu 30 Januar 2023 NumPy
  1. Syntax der Funktion numpy.linalg.inv()
  2. Beispiel-Codes: numpy.linalg.inv() Methode
  3. Beispiel-Codes: numpy.linalg.inv() Methode mit Matrix Eingabe
  4. Beispielcodes: numpy.linalg.inv() Mit Matrix Array
Python Numpy.linalg.inv() - Inverse Matrix

Die Funktion Numpy.linalg.inv() berechnet den Kehrwert der gegebenen Matrix.

Syntax der Funktion numpy.linalg.inv()

numpy.linalg.inverse(arr)

Parameter

arr Eingabe-Array

Zurück

Sie gibt die Inverse der gegebenen Matrix zurück.

Er erhöht den Fehler, wenn die gegebene Matrix nicht quadratisch ist oder die Inversion fehlschlägt.

Beispiel-Codes: numpy.linalg.inv() Methode

import numpy as np

arr = np.array([[1, 3], [5, 7]])

arr_inv = np.linalg.inv(arr)

print(arr_inv)

Ausgabe:

[[-0.875  0.375]
 [ 0.625 -0.125]]

Beispiel-Codes: numpy.linalg.inv() Methode mit Matrix Eingabe

Wenn die gegebene Eingabe eine numpy Matrix ist, dann gibt inv() auch eine Matrix zurück.

import numpy as np

arr = np.matrix([[1, 3], [5, 7]])

arr_inv = np.linalg.inv(arr)

print(arr_inv, type(arr_inv))

Ausgabe:

[[-0.875  0.375]
 [ 0.625 -0.125]] <class 'numpy.matrix'>

Beispielcodes: numpy.linalg.inv() Mit Matrix Array

import numpy as np

arr = np.array([[[1, 3], [5, 7]], [[2, 5], [4, 6]]])

arr_inv = np.linalg.inv(arr)

print(arr_inv)

Ausgabe:

[[[-0.875  0.375]
  [ 0.625 -0.125]]

 [[-0.75   0.625]
  [ 0.5   -0.25 ]]]

Wenn das Eingabe-Array aus mehreren Matrizen besteht, berechnet die numpy linalg.inv() Methode die Inverse von ihnen auf einmal.

Genießen Sie unsere Tutorials? Abonnieren Sie DelftStack auf YouTube, um uns bei der Erstellung weiterer hochwertiger Videoanleitungen zu unterstützen. Abonnieren
Autor: Jinku Hu
Jinku Hu avatar Jinku Hu avatar

Founder of DelftStack.com. Jinku has worked in the robotics and automotive industries for over 8 years. He sharpened his coding skills when he needed to do the automatic testing, data collection from remote servers and report creation from the endurance test. He is from an electrical/electronics engineering background but has expanded his interest to embedded electronics, embedded programming and front-/back-end programming.

LinkedIn Facebook