TUTORIALAI 与数据科学FETCHED
PyTorch torch.asarray 函数
PyTorch torch.asarray 函数 Pytorch torch 参考手册 torch.asarray 是 PyTorch 中用于将数据转换为张量数组的函数。 函数定义 torch.asarray(data, dtype, device) 使用示例 实例 [mycode4 type='python'] import torch # 从列表转换 x = torch.asarray([1..
更新于 2026/7/16
教程详情页默认 noindex。
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 参考手册