PyTorch torch.asarray function
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
]
)
(
x
)
Convert from a NumPy array
import
numpy
as
np
arr
=
np.
array
(
[
4
,
5
,
6
]
)
y
=
torch.
asarray
(
arr
)
(
y
)