PyTorch torch.asarray Function
PyTorch torch Reference Manual
torch.asarrayis a function in PyTorch used to convert data into tensor arrays.
Function Definition
torch.asarray(data, dtype, device)
Usage Example
Example
import torch
# Convert from list
x = torch.asarray([1, 2, 3])
print(x)
# Convert from NumPy array
import numpy as np
arr = np.array([4, 5, 6])
y = torch.asarray(arr)
print(y)
# Convert from list
x = torch.asarray([1, 2, 3])
print(x)
# Convert from NumPy array
import numpy as np
arr = np.array([4, 5, 6])
y = torch.asarray(arr)
print(y)
Other Extensions