PyTorch torch.linalg.det 関数
torch.linalg.detは PyTorch の線形代数モジュールで行列の行列式を計算するための関数です。これはtorch.detの推奨代替関数です。
関数定義
torch.linalg.det(A)
引数:
A(Tensor): 入力正方行列。
戻り値:
torch.Tensor: 行列の行列式を返します。
使用例
例
import torch
# 正方行列を作成
A = torch.tensor([[1.0, 2.0, 3.0],
[0.0, 4.0, 5.0],
[0.0, 0.0, 6.0]])
# 行列式を計算
det_A = torch.linalg.det(A)
print("行列 A:")
print(A)
print("行列式:")
print(det_A)
# 正方行列を作成
A = torch.tensor([[1.0, 2.0, 3.0],
[0.0, 4.0, 5.0],
[0.0, 0.0, 6.0]])
# 行列式を計算
det_A = torch.linalg.det(A)
print("行列 A:")
print(A)
print("行列式:")
print(det_A)
出力結果は次のとおりです:
矩阵 A:
tensor([[1., 2., 3.],
[0., 4., 5.],
[0., 0., 6.]])
行列式:
tensor(24.)
その他の拡張