首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

PyTorch入门视频笔记-从数组、列表对象中创建Tensor

PyTorch 从数组或者列表对象中创建 Tensor 有四种方式: torch.Tensor torch.tensor torch.as_tensor torch.from_numpy >>> import...isinstance(tensor_list_c, torch.Tensor) , tensor_list_c.type()) True torch.LongTensor # 方式四:使用torch.from_numpy...函数 >>> tensor_array_d = torch.from_numpy(array) # tensor_list_d = torch.from_numpy(list) error code...只能将数组转换为 Tensor(为 torch.from_numpy 函数传入列表,程序会报错); 从程序的输出结果可以看出,四种方式最终都将数组或列表转换为 Tensor(使用 isinstance...如果考虑性能,推荐使用 torch.as_tensor(torch.from_numpy 只能接受数组类型),因为使用 torch.as_tensor 生成的 tensor 会和数组共享内存,从而节省内存的开销

4.8K20
领券