PyTorch torch.frombuffer Function
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)
import array
# Create from array
arr = array.array('i', [1, 2, 3, 4, 5])
x = torch.frombuffer(arr, dtype=torch.int32)
print(x)
Other Extensions