PyTorch torch.frombuffer Function


Pytorch torch 参考手册PyTorch torch Reference Manual

torch.frombufferIt is a function in PyTorch used to create a one-dimensional tensor from a buffer.

Function Definition

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

Usage Example

Example

import torch
import array

# Create from array
arr = array.array('i', [1, 2, 3, 4, 5])
x = torch.frombuffer(arr, dtype=torch.int32)

print(x)

Pytorch torch 参考手册PyTorch torch Reference Manual

Other Extensions