公众号【计算机视觉联盟】后台回复【PyTorch】可以获得PyTorch学习教程pdf版
通过torch.tensor创建张量
arr = np.ones((3,3))
print("由np.ones生成的数据:n",arr)
print("ndarray的数据类型:",arr.dtype,"n")
#t = torch.tensor(arr, device='cuda')
t = torch.tensor(arr)
print("torch.tensor创建好的Tensor:n",t)
输出结果:
由np.ones生成的数据:
[[1. 1. 1.]
[1. 1. 1.]
[1. 1. 1.]]
ndarray的数据类型:float64
torch.tensor创建好的Tensor:
tensor([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]], dtype=torch.float64)
Process finished with exit code 0
最后
以上就是现代冷风最近收集整理的关于PyTorch | torch.tensor使用方法,如何使用torch.tensor的全部内容,更多相关PyTorch内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复