PyTorch

スポンサーリンク
Python

Tensor配列の最大値と最小値を同時に取得するtorch.aminmax【PyTorch】

PyTorchのTensor配列の最大値と最小値を同時に取得するにはtorch.aminmaxを使用する。 torch.aminmax - PyTorch Docs v1.12 torch.aminmaxの使い方 t...
Python

【PyTorch】Tensor配列をシフト(移動)させるtorch.roll

PyTorchでTensor配列をシフト(移動)させるtorch.rollを使う。 torch.roll - PyTorch Docs v1.12 torch.rollの使い方 1次元配列の場合は、torch.rol...
Python

PyTorchのバージョンを確認 (version)

PyTorchのバージョンする方法をいくつか紹介する。 __version__属性を使う方法 PyTrochのversion属性を使うことで、バージョン番号を取得する。 import torch print(torch...
Python

【PyTorch】Tensor配列を反転するtorch.flip、torch.flipud、torch.fliplr

PyTorchのTensor配列を上下左右反転させるにはtorch.flipを使う。他にも、上下方向に反転させるtorch.flipud、左右方向に反転させるtorch.fliplrがある。 torch.flip - PyTorc...
Python

1次元配列の内積を計算するtorch.dot【PyTorch】

PyTorchのTensor配列の内積を計算するには、torch.dotを使用する。 torch.dot - PyTorch Docs v1.12 torch.dotの使い方 torch.dotを使うことで、内積を計...
Machine Learning

ValueError: Expected more than 1 value per channel when training, got input size torch.Sizeの解決方法【PyTorch】

PyTorchで学習を行なっていると、以下エラーが出たので対処方法をメモしていく。 ValueError: Expected more than 1 value per channel when training, got inp...
Python

【PyTorch】既存の次元(軸)に沿って結合するtorch.cat

PyTorchのTensor配列を既存の次元(軸)に沿って結合するにはtorch.catを使う。 torch.cat - PyTorch v1.12 Docs torch.catの使い方 以下のTensor配列を用い...
Python

【PyTorch】条件に応じた処理を行うtorch.where

PyTorchのTensor配列に対して、条件を満たす要素に対して処理を行うには、torch.whereを使う。 torch.where - PyTorch v1.12 Docs torch.whereの使い方 to...
Python

【PyTorch】Tensor配列のサイズ1の次元を削除するtorch.squeeze、指定した位置にサイズ1の次元を挿入するtorch.unsqueeze

Tensor配列のサイズ1の次元を削除するにはtorch.squeeze、指定した位置にサイズ1の次元を挿入するにはtorch.unsqueezeを使用する。 torch.squeeze - PyTorch v1.12 Docs ...
Python

【PyTorch】Tensor配列にNaNが含まれているか判定するtorch.isnan、nanを指定した値に置き換えるtorch.nan_to_num

PyTorchでTensor配列にNaNが含まれているか判定するにはtorch.isnan、NaNを指定した値に置き換えるにはtorch.nan_to_numを使う。 torch.isnanの使い方 torch.isnanにT...