この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
プログラミング:python:ディープラーニング:pytorch:基本的な使い方 [2019/07/15 07:27] sotoyama [基本] |
プログラミング:python:ディープラーニング:pytorch:基本的な使い方 [2019/07/15 07:37] (現在) sotoyama [numpy] |
||
|---|---|---|---|
| ライン 76: | ライン 76: | ||
| y = torch.rand(5, 3) | y = torch.rand(5, 3) | ||
| ret = torch.empty(5, 3) | ret = torch.empty(5, 3) | ||
| + | |||
| + | # その1 | ||
| torch.add(x, y, out=ret) | torch.add(x, y, out=ret) | ||
| + | |||
| + | # その2 | ||
| + | y.add(x) | ||
| </code> | </code> | ||
| - | === XXXX === | + | |
| + | === tensor→numpyへの変換 === | ||
| <code python> | <code python> | ||
| + | a = torch.ones(5) | ||
| + | b = a.numpy() | ||
| + | </code> | ||
| + | === numpy→tensorへの変換 === | ||
| + | <code python> | ||
| + | import numpy as np | ||
| + | a = np.ones(5) | ||
| + | b = torch.from_numpy(a) | ||
| </code> | </code> | ||
| + | |||
| === XXXX === | === XXXX === | ||