PyTorch torch.maximum 函数
torch.maximum 是 PyTorch 中用于逐元素取最大值的函数。返回两个张量对应元素的最大值组成的新张量。
函数定义
torch.maximum(input, other)
使用示例
实例
import torch
# 创建两个张量
x = torch.tensor([3, 1, 4])
y = torch.tensor([1, 5, 2])
# 逐元素取最大值
result = torch.maximum(x, y)
print(result)
# 创建两个张量
x = torch.tensor([3, 1, 4])
y = torch.tensor([1, 5, 2])
# 逐元素取最大值
result = torch.maximum(x, y)
print(result)
输出结果为:
tensor([3, 5, 4])

Pytorch torch 参考手册