PyTorch torch.det 関数
torch.detPyTorch で正方行列の行列式を計算するための関数です。
関数定義
torch.det(input)
使用例
例
import torch
# 2x2 行列を作成
a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
# 行列式を計算
y = torch.det(a)
print(y)
# 2x2 行列を作成
a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
# 行列式を計算
y = torch.det(a)
print(y)
出力結果は次のとおりです:
tensor(-2.)
torch.logdet 関数
torch.logdetPyTorch で行列式の対数を計算する関数です。行列式が正の場合は log(det) を返します。行列式が負または複素数の場合、処理方法が異なります。
関数定義
torch.logdet(input)
使用例
例
import torch
# 2x2 行列を作成
a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
# 行列式の対数を計算
y = torch.logdet(a)
print(y)
# 2x2 行列を作成
a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])
# 行列式の対数を計算
y = torch.logdet(a)
print(y)
出力結果は次のとおりです:
tensor(nan)
その他の拡張
Pytorch torch リファレンスマニュアル