TUTORIALAI 与数据科学FETCHED
PyTorch torch.maximum 函数
PyTorch torch.maximum 函数 Pytorch torch 参考手册 torch.maximum 是 PyTorch 中用于逐元素取最大值的函数。返回两个张量对应元素的最大值组成的新张量。 函数定义 torch.maximum(input, other) 使用示例 实例 [mycode4 type='python'] import torch # 创建两个张量 x = torc..
更新于 2026/7/16
教程详情页默认 noindex。
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 参考手册