PyTorch torch.log2 函数

约 208 字 更新于 2026-11-18 5iyo.com

PyTorch torch.log2 函数


torch.log2 是 PyTorch 中用于计算以2为底的对数函数。

函数定义

torch.log2(input, out)

使用示例

实例

import torch

# 计算以2为底的对数
x = torch.tensor([1, 2, 4, 8, 16])
result = torch.log2(x)
print(result)