PyTorch torch.asarray 関数
torch.asarrayPyTorch でデータをテンソル配列に変換するために使用する関数です。
関数定義
torch.asarray(data, dtype, device)
使用例
例
import torch
# リストから変換
x = torch.asarray([1, 2, 3])
print(x)
# NumPy 配列から変換
import numpy as np
arr = np.array([4, 5, 6])
y = torch.asarray(arr)
print(y)
# リストから変換
x = torch.asarray([1, 2, 3])
print(x)
# NumPy 配列から変換
import numpy as np
arr = np.array([4, 5, 6])
y = torch.asarray(arr)
print(y)
その他の拡張
Pytorch torch リファレンスマニュアル