PyTorch torch.flipud Funktion
PyTorch torch-Referenzhandbuch
torch.flipudEine Funktion in PyTorch, mit der ein Tensor vertikal gespiegelt wird (vertikale Spiegelung).
Funktionsdefinition
torch.flipud(input)
Anwendungsbeispiele
Beispiel
import torch
# Einen 2D-Tensor vertikal spiegeln
x = torch.arange(12).reshape(3, 4)
print("Original-Tensor:")
print(x)
result = torch.flipud(x)
print("Auf den Kopf gestellt:")
print(result)
# Eine quadratische Matrix auf den Kopf stellen
y = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("3x3 quadratische Matrix:")
print(y)
result = torch.flipud(y)
print("Auf den Kopf gestellt:")
print(result)
# Einen 1D-Tensor auf den Kopf stellen
z = torch.tensor([1, 2, 3, 4])
result = torch.flipud(z)
print("1D-Tensor [1, 2, 3, 4]:")
print("Auf den Kopf gestellt:", result)
# Einen 2D-Tensor vertikal spiegeln
x = torch.arange(12).reshape(3, 4)
print("Original-Tensor:")
print(x)
result = torch.flipud(x)
print("Auf den Kopf gestellt:")
print(result)
# Eine quadratische Matrix auf den Kopf stellen
y = torch.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print("3x3 quadratische Matrix:")
print(y)
result = torch.flipud(y)
print("Auf den Kopf gestellt:")
print(result)
# Einen 1D-Tensor auf den Kopf stellen
z = torch.tensor([1, 2, 3, 4])
result = torch.flipud(z)
print("1D-Tensor [1, 2, 3, 4]:")
print("Auf den Kopf gestellt:", result)
Die Ausgabe ist:
原始张量:
tensor([[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]])
上下翻转:
tensor([[ 8, 9, 10, 11],
[ 4, 5, 6, 7],
[ 0, 1, 2, 3]])
3x3 方阵:
tensor([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
上下翻转:
tensor([[7, 8, 9],
[4, 5, 6],
[1, 2, 3]])
一维张量 [1, 2, 3, 4]:
上下翻转: tensor([4, 3, 2, 1])
Andere Erweiterungen