PyTorch torch.lu_unpack-Funktion
PyTorch torch-Referenzhandbuch
torch.lu_unpackEs ist eine Funktion in PyTorch, die verwendet wird, um die Matrizen L, U und P aus dem Ergebnis der LU-Zerlegung zu entpacken.
Funktionsdefinition
torch.lu_unpack(LU_data, LU_pivots, unpack_data=True, out=None)
Parameters:
LU_data(Tensor): Die aus der LU-Zerlegung erhaltene Matrix.LU_pivots(Tensor): Die Pivot-Indizes aus der LU-Zerlegung.unpack_data(bool, optional): Ob die Daten entpackt werden sollen. Standardwert ist True.out(tuple, optional): Ausgabetupel.
Rückgabewert:
tuple: Gibt das Tupel (pivot, L, U) zurück.
Anwendungsbeispiel
Beispiel
import torch
# Matrix erstellen
A = torch.tensor([[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0]])
# LU-Zerlegung
LU, pivots = torch.lu(A)
# L, U, P entpacken
P, L, U = torch.lu_unpack(LU, pivots)
print("Matrix A:")
print(A)
print("nPermutationsmatrix P:")
print(P)
print("nUntere Dreiecksmatrix L:")
print(L)
print("nObere Dreiecksmatrix U:")
print(U)
print("nÜberprüfung: P @ L @ U =")
print(P @ L @ U)
# Matrix erstellen
A = torch.tensor([[1.0, 2.0, 3.0],
[4.0, 5.0, 6.0],
[7.0, 8.0, 9.0]])
# LU-Zerlegung
LU, pivots = torch.lu(A)
# L, U, P entpacken
P, L, U = torch.lu_unpack(LU, pivots)
print("Matrix A:")
print(A)
print("nPermutationsmatrix P:")
print(P)
print("nUntere Dreiecksmatrix L:")
print(L)
print("nObere Dreiecksmatrix U:")
print(U)
print("nÜberprüfung: P @ L @ U =")
print(P @ L @ U)
Das Ausgabeergebnis ist:
矩阵 A:
tensor([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]])
置换矩阵 P:
tensor([[0., 0., 1.],
[1., 0., 0.],
[0., 1., 0.]])
下三角矩阵 L:
tensor([[1.0000, 0.0000, 0.0000],
[0.1429, 1.0000, 0.0000],
[0.5714, 0.5000, 1.0000]])
上三角矩阵 U:
tensor([[7.0000, 8.0000, 9.0000],
[0.0000, 0.8571, 1.7143],
[0.0000, 0.0000, 0.0000]])
验证: P @ L @ U =
tensor([[1., 2., 3.],
[4., 5., 6.],
[7., 8., 9.]])
Andere Erweiterungen