,


Pytorch torch 参考手册PyTorch torch-Referenzhandbuch

torch.atleast_3dist eine Funktion in PyTorch, die verwendet wird, um Eingabetensoren in mindestens 3 Dimensionen umzuwandeln. Wenn die Eingabe weniger als 3 Dimensionen hat, werden automatisch Dimensionen hinzugefügt, um sie 3-dimensional zu machen.

]]) Form: torch.Size([3, 1, 1])

torch.atleast_3d(*tensors)

Anwendungsbeispiel

]]) Form: torch.Size([1, 1, 1])

import torch

# Skalar in 3D-Tensor umwandeln
x = torch.atleast_3d(5)
print("Nach Skalarkonvertierung:", x, "Form:", x.shape)
# Ausgabe: Nach der Skalarumwandlung: tensor([[

# 1D-Tensor in 3D-Tensor umwandeln
x = torch.tensor([1, 2, 3])
y = torch.atleast_3d(x)
print("1D zu 3D:", y, "Form:", y.shape)
# Ausgabe: 1D zu 3D: tensor([[

# 2D-Tensor in 3D-Tensor umwandeln
x = torch.tensor([[1, 2], [3, 4]])
y = torch.atleast_3d(x)
print("2D zu 3D:", y, "Form:", y.shape)
# Ausgabe: 2D zu 3D: tensor([[[1, 2], [3, 4]]]) Form: torch.Size([1, 2, 2])

# Ein Tensor, der bereits 3D ist, bleibt unverändert
x = torch.tensor([[[1, 2], [3, 4]]])
y = torch.atleast_3d(x)
print("3D-Tensor:", y, "Form:", y.shape)

Pytorch torch 参考手册PyTorch torch-Referenzhandbuch

Andere Erweiterungen