Install pytorch 使用 torch 的例子

        如果不知道怎么开始和安装软件 从这里开始  

 如果需要GPU版本,请选择CUDA,而不是CPU

PyTorchicon-default.png?t=N7T8https://pytorch.org/

Python 3.8.13 | packaged by conda-forge | (default, Mar 25 2022, 06:04:10) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> x=torch.empty(5,3)
>>> print(x)
tensor([[-8.7848e-11,  4.5785e-41, -8.7479e-11],
        [ 4.5785e-41, -8.7848e-11,  4.5785e-41],
        [ 2.8026e-45,  0.0000e+00,  0.0000e+00],
        [ 4.5785e-41,  0.0000e+00,  0.0000e+00],
        [ 0.0000e+00,  4.5785e-41, -9.0661e-11]])
>>> x=torch.rand(7,4) 
>>> print(x)
tensor([[0.6772, 0.3902, 0.2330, 0.9701],
        [0.6920, 0.7725, 0.3087, 0.0431],
        [0.3625, 0.7056, 0.5657, 0.2941],
        [0.7590, 0.8172, 0.5953, 0.0298],
        [0.1016, 0.5372, 0.0127, 0.6681],
        [0.5398, 0.6971, 0.6637, 0.4160],
        [0.7463, 0.1475, 0.3829, 0.4958]])
>>> x = torch.zeros(5, 3, dtype=torch.long)
>>> print(x)
tensor([[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]])

>>> x = torch.tensor([[5.5, 3],[6.5,5]])
>>> print(x)
tensor([[5.5000, 3.0000],
        [6.5000, 5.0000]]) 

我的领悟:张量等于多维数组(维数大于3)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

HehuaTang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值