Python/torch:修订间差异
来自康健生活
< Python
创建页面,内容为“== 引言 == {{shc|<syntaxhighlight lang="bash"> pip3 install torch</syntaxhighlight>|$|/home/kangkk}}” |
无编辑摘要 |
||
| (未显示同一用户的2个中间版本) | |||
| 第1行: | 第1行: | ||
== 引言 == | == 引言 == | ||
== 安装 == | |||
{{shc|<syntaxhighlight lang="bash"> | {{shc|<syntaxhighlight lang="bash"> | ||
pip3 install torch</syntaxhighlight>|$|/home/kangkk}} | pip3 install torch</syntaxhighlight>|$|/home/kangkk}} | ||
=== 验证 === | |||
{{Hc|testtorch.py|<syntaxhighlight lang="python"> | |||
import torch | |||
x = torch.rand(5, 3) | |||
print(x) | |||
</syntaxhighlight>}} | |||
开始验证。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
python3 testtorch.py | |||
</syntaxhighlight>|<syntaxhighlight lang="bash">tensor([[0.2115, 0.1338, 0.1398], | |||
[0.9219, 0.2041, 0.9872], | |||
[0.5002, 0.3102, 0.5110], | |||
[0.0139, 0.3722, 0.8301], | |||
[0.8480, 0.6488, 0.3080]]) | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
是否启用了 CUDA 驱动程序。 | |||
{{Hc|testtorchiscuda.py|<syntaxhighlight lang="python"> | |||
import torch | |||
x = torch.cuda.is_available() | |||
print(x) | |||
</syntaxhighlight>}} | |||
开始验证。 | |||
{{Shc_out|<syntaxhighlight lang="bash"> | |||
python3 testtorchiscuda.py</syntaxhighlight>|<syntaxhighlight lang="bash">True | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
2021年11月7日 (日) 10:32的最新版本
引言
安装
/home/kangkk
pip3 install torch
验证
testtorch.py
import torch
x = torch.rand(5, 3)
print(x)
开始验证。
[jian@kang /home/kangkk]$
python3 testtorch.py
tensor([[0.2115, 0.1338, 0.1398],
[0.9219, 0.2041, 0.9872],
[0.5002, 0.3102, 0.5110],
[0.0139, 0.3722, 0.8301],
[0.8480, 0.6488, 0.3080]])
是否启用了 CUDA 驱动程序。
testtorchiscuda.py
import torch
x = torch.cuda.is_available()
print(x)
开始验证。
[jian@kang /home/kangkk]$
python3 testtorchiscuda.py
True
No categories