PyTorch torch.frombuffer 関数


Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

torch.frombufferPyTorch でバッファから1次元テンソルを作成する関数です。

関数定義

torch.frombuffer(buffer, dtype, count, offset)

使用例

実例

import torch
import array

# array から作成
arr = array.array('i', [1, 2, 3, 4, 5])
x = torch.frombuffer(arr, dtype=torch.int32)

print(x)

Pytorch torch 参考手册Pytorch torch リファレンスマニュアル

その他の拡張