PyTorch torch.xlogy 函数

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

PyTorch torch.xlogy 函数


torch.xlogy 是 PyTorch 中用于逐元素计算 input * log(other) 的函数。对于 other 为 0 的情况,会返回 0。

函数定义

torch.xlogy(input, other, out=None)

使用示例

实例

import torch

# 计算 x * log(y)
x = torch.tensor([1.0, 2.0, 3.0])
y = torch.tensor([2.0, 3.0, 4.0])
result = torch.xlogy(x, y)
print(result)