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

PyTorch torch.asarray function

PyTorch torch.asarray function


PyTorch torch reference manual PyTorch torch reference manual

torch.asarray is a function in PyTorch used to convert data into a tensor array.

Function definition

torch.asarray(data, dtype, device)


Usage examples

Example

import

torch

Convert from a list

x

=

torch.

asarray

(

[

1

,

2

,

3

]

)

print

(

x

)

Convert from a NumPy array

import

numpy

as

np

arr

=

np.

array

(

[

4

,

5

,

6

]

)

y

=

torch.

asarray

(

arr

)

print

(

y

)


PyTorch torch reference manual PyTorch torch reference manual