Pytorch:官方教程 -- A 60 MINUTE BLITZ

版本 : pytorch 1.0.0.dev20181128

一、Pytorch简介

  1. 可以在GPU高速运行的numpy替代库

  2. 一个灵活快速的深度学习框架
  3. 主要包含 tensor nn.module 两个核心模块
########### Tensor定义 ###########
x1 = torch.empty(2, 3)
x2 = torch.rand(2, 3)
x3 = torch.zeros(2, 3, dtype=torch.long)
x4 = torch.tensor([5.5, 3])
print(x1)
'''
tensor([[0., 0., 0.],
        [0., 0., 0.]])
'''
print(x2)
'''
tensor([[0.2616, 0.6785, 0.9963],
        [0.3585, 0.5911, 0.1730]])
'''
print(x3)
'''
tensor([[0, 0, 0],
        [0, 0, 0]])
'''
print(x4)
'''
tensor([5.5000, 3.0000])
'''
########### Tensor常用属性 ###########
x = torch.empty(2, 3)
print(x)
'''
tensor([[0.0000e+00, 0.0000e+00, 1.6809e+36],
        [7.9594e-43, 0.0000e+00, 0.0000e+00]])
'''
print(x.size())             # torch.Size([2, 3]), 本质是tuple
print(x.type())             # torch.FloatTensor
print(x.requires_grad)      # False
print(x.grad)               # None
print(x.grad_fn)            # None
########### Tensor操作举例:加法 ###########
x = torch.ones(2, 3)
y = torch.zeros(2, 3)
# 方式一
print(x + y)
# 方式二
print(torch.add(x, y))
# 方式三
result = torch.empty(2, 3)
torch.add(x, y, out=result)
print(result)
# 方式四:Any operation that mutates a tensor
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值