PyTorch torch.flip-Funktion
PyTorch torch Referenzhandbuch
torch.flipEs ist eine Funktion in PyTorch, mit der ein Tensor entlang der angegebenen Dimension gespiegelt wird.
Funktionsdefinition
torch.flip(input, dims)
Anwendungsbeispiel
Beispiel
import torch
x = torch.arange(8).reshape(2, 4)
print("Original:")
print(x)
print("Horizontale Spiegelung:")
print(torch.flip(x, dims=[1]))
print("Vertikale Spiegelung:")
print(torch.flip(x, dims=[0]))
x = torch.arange(8).reshape(2, 4)
print("Original:")
print(x)
print("Horizontale Spiegelung:")
print(torch.flip(x, dims=[1]))
print("Vertikale Spiegelung:")
print(torch.flip(x, dims=[0]))
Das Ausgabeergebnis ist:
原始:
tensor([[0, 1, 2, 3],
[4, 5, 6, 7]])
水平翻转:
tensor([[3, 2, 1, 0],
[7, 6, 5, 4]])
垂直翻转:
tensor([[4, 5, 6, 7],
[0, 1, 2, 3]])
Andere Erweiterungen