Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

PyTorch torch.frombuffer function

PyTorch torch.frombuffer function


PyTorch torch reference manual PyTorch torch reference manual

torch.frombuffer A function in PyTorch for creating a 1D tensor from a buffer.

Function definition

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


Usage examples

Example

import

torch

import

array

Create from an array

arr

=

array

.

array

(

'i'

,

[

1

,

2

,

3

,

4

,

5

]

)

x

=

torch.

frombuffer

(

arr

,

dtype

=

torch.

int32

)

print

(

x

)


PyTorch torch reference manual PyTorch torch reference manual