PyTorch torch.asarray 函数
torch.asarray 是 PyTorch 中用于将数据转换为张量数组的函数。
函数定义
torch.asarray(data, dtype, device)
使用示例
实例
import torch
# 从列表转换
x = torch.asarray([1, 2, 3])
print(x)
# 从 NumPy 数组转换
import numpy as np
arr = np.array([4, 5, 6])
y = torch.asarray(arr)
print(y)
# 从列表转换
x = torch.asarray([1, 2, 3])
print(x)
# 从 NumPy 数组转换
import numpy as np
arr = np.array([4, 5, 6])
y = torch.asarray(arr)
print(y)

Pytorch torch 参考手册