TUTORIALAI 与数据科学FETCHED

PyTorch torch.det 函数

PyTorch torch.det 函数 Pytorch torch 参考手册 torch.det 是 PyTorch 中用于计算方阵行列式的函数。 函数定义 torch.det(input) 使用示例 实例 [mycode4 type='python'] import torch # 创建 2x2 矩阵 a = torch.tensor([[1.0, 2.0], [3.0, 4.0]]) #..

更新于 2026/7/16

教程详情页默认 noindex。

PyTorch torch.det 函数


Pytorch torch 参考手册 Pytorch torch 参考手册

torch.det 是 PyTorch 中用于计算方阵行列式的函数。

函数定义

torch.det(input)

使用示例

实例

import torch

# 创建 2x2 矩阵
a = torch.tensor([[1.0, 2.0], [3.0, 4.0]])

# 计算行列式
y = torch.det(a)
print(y)

输出结果为:

tensor(-2.)

torch.logdet 函数

torch.logdet 是 PyTorch 中用于计算行列式对数的函数。当行列式为正时,返回 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)

输出结果为:

tensor(nan)

Pytorch torch 参考手册 Pytorch torch 参考手册