PyTorch torch.column_stack 関数
torch.column_stackPyTorch でテンソルを列方向にスタックするための関数です。
関数定義
torch.column_stack(tensors, *, out=None)
使用例
例
import torch
# 1次元テンソルの列スタック
x1 = torch.tensor([1, 2, 3])
x2 = torch.tensor([4, 5, 6])
result = torch.column_stack([x1, x2])
print("1次元テンソルの列スタック:")
print(f" x1: {x1}")
print(f" x2: {x2}")
print(f" column_stack:n{result}")
# 2次元テンソルの列スタック
y1 = torch.tensor([[1], [2], [3]])
y2 = torch.tensor([[4], [5], [6]])
result = torch.column_stack([y1, y2])
print("n2次元テンソルの列スタック:")
print(f" y1:n{y1}")
print(f" y2:n{y2}")
print(f" column_stack:n{result}")
# 複数のテンソルの列スタック
z1 = torch.tensor([1, 2, 3])
z2 = torch.tensor([4, 5, 6])
z3 = torch.tensor([7, 8, 9])
result = torch.column_stack([z1, z2, z3])
print("n複数の1次元テンソルの列スタック:")
print(f" result:n{result}")
# 1次元テンソルの列スタック
x1 = torch.tensor([1, 2, 3])
x2 = torch.tensor([4, 5, 6])
result = torch.column_stack([x1, x2])
print("1次元テンソルの列スタック:")
print(f" x1: {x1}")
print(f" x2: {x2}")
print(f" column_stack:n{result}")
# 2次元テンソルの列スタック
y1 = torch.tensor([[1], [2], [3]])
y2 = torch.tensor([[4], [5], [6]])
result = torch.column_stack([y1, y2])
print("n2次元テンソルの列スタック:")
print(f" y1:n{y1}")
print(f" y2:n{y2}")
print(f" column_stack:n{result}")
# 複数のテンソルの列スタック
z1 = torch.tensor([1, 2, 3])
z2 = torch.tensor([4, 5, 6])
z3 = torch.tensor([7, 8, 9])
result = torch.column_stack([z1, z2, z3])
print("n複数の1次元テンソルの列スタック:")
print(f" result:n{result}")
出力結果は次のとおりです:
一维张量列堆叠:
x1: tensor([1, 2, 3])
x2: tensor([4, 5, 6])
column_stack:
tensor([[1, 4],
[2, 5],
[3, 6]])
二维张量列堆叠:
y1:
tensor([[1],
[2],
[3]])
y2:
tensor([[4],
[5],
[6]])
column_stack:
tensor([[1, 4],
[2, 5],
[3, 6]])
多个一维张量列堆叠:
result:
tensor([[1, 4, 7],
[2, 5, 8],
[3, 6, 9]])
その他の拡張
Pytorch torch リファレンスマニュアル