この文書の現在のバージョンと選択したバージョンの差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
プログラミング:python:ディープラーニング:pytorch:基本的な使い方 [2019/07/15 07:21] sotoyama |
プログラミング:python:ディープラーニング:pytorch:基本的な使い方 [2019/07/15 07:37] (現在) sotoyama [numpy] |
||
|---|---|---|---|
| ライン 70: | ライン 70: | ||
| === テンソルの演算 === | === テンソルの演算 === | ||
| + | 通常の四則演算(+, -, *, /)も使用できるが、他の方法もあります。 | ||
| <code python> | <code python> | ||
| + | # 加算 | ||
| + | x = torch.rand(5, 3) | ||
| + | y = torch.rand(5, 3) | ||
| + | ret = torch.empty(5, 3) | ||
| + | # その1 | ||
| + | torch.add(x, y, out=ret) | ||
| + | |||
| + | # その2 | ||
| + | y.add(x) | ||
| </code> | </code> | ||
| + | |||
| + | |||
| + | === tensor→numpyへの変換 === | ||
| + | <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> | ||
| + | |||
| + | |||
| + | === XXXX === | ||
| + | <code python> | ||
| + | |||
| + | </code> | ||
| + | === XXXX === | ||
| + | <code python> | ||
| + | |||
| + | </code> | ||
| + | === XXXX === | ||
| + | <code python> | ||
| + | |||
| + | </code> | ||
| + | === XXXX === | ||
| + | <code python> | ||
| + | |||
| + | </code> | ||
| + | === XXXX === | ||
| + | <code python> | ||
| + | |||
| + | </code> | ||
| + | === XXXX === | ||
| + | <code python> | ||
| + | |||
| + | </code> | ||
| + | |||
| + | |||
| + | |||