Takeru@Software Engineer

スポンサーリンク
Python

【PyTorch】平均値と中央値を算出するtorch.mean、torch.median

PyTorchのTensor配列で平均値を求めるにはtorch.mean、torch.nanmean、中央値を求めるにはtorch.median、torch.nanmedianを使う。 torch.mean - PyTorch v2.2 D...
librosa

【PyTorch/librosa】Pythonで音声/音楽データをリサンプリングする

librosaとPyTorchを用いて、Pythonで音声/音楽データ(波形)のリサンプリングを行う。Numpyのndarray配列をリサンプリングしたい場合はlibrosaを用い、PyTorchのTensor配列をリサンプリングしたい場合...
Image

OpenCVで画像をリサイズ(拡大・縮小)するcv2.resize【Python】

OpenCVで像をリサイズ(拡大・縮小)するには、cv2.resizeを使う。 cv2.resizeの使い方 今回用いるサンプル画像をWEBからダウロード、保存します。 • 関連記事 – 【最速】PythonでWEB上の画像をダウンロードし...
Python

【PyTorch】Tensor配列のユニークな要素の値、位置、数を取得するtorch.unique

PyTorchのTensor配列のユニーク(一意)な要素の値、位置、数(カウント)を取得するにはtorch.uniqueを使う。 torch.unique - PyTorch v2.2 Docs torch.uniqueの使い方 torch...
Python

PyTorchでTensor配列の符号を取得するtorch.sign

PyTorchでTensor配列の符号を取得するには、torch.sign()を使う。 torch.sign - PyTorch v2.2 Docs torch.signの使い方 torch.signの引数にTensor配列を指定する。負の...
Python

【PyTorch】ランダムな整数の順列を生成するtorch.randperm【乱数】

torch.randpermの使い方 ランダムな整数の順列を生成するには、torch.randperm()を使う。 torch.randperm - PyTroch v2.2 Docs 引数にnを指定すると、0からn-1までの順列が作成され...
Python

【PyTorch】Tensor配列の最大値・最小値のインデックスを取得するtorch.argmax、torch.argmin【位置】

PyTorchでTensor配列の最大値・最小値となる要素のインデックスを取得するには、torch.argmax、torch.argminを使う。 torch.argmax - PyTorch v2.2 Docs torch.argmin ...
Numpy

Numpyでランダム(乱数)な整数を生成するnumpy.random.randint【Python】

Numpyでランダムな整数を生成するにはnumpy.random.randintを用いる。 numpy.random.randint - Numpy API Reference numpy.random.randint 第一引数lowと第二...
Numpy

【PyTorch】Tensorとndarrayの変換方法について【Numpy】

PyTorchのTensor配列と、Numpyのndarray配列の変換方法についてまとめました。とりあえず直ぐに使いたい方向けのコードは以下 # Numpy > Tensor a = torch.from_numpy(a).clone()...
Python

PyTochで最も近い整数に丸めるtorch.round

PyTorchで最も近い整数に丸めるにはtorch.roundを使う。 torch.round — PyTorch 2.2 documentation torch.roundの使い方 torch.roundの第一引数inputにTensor...