import torch
import torch.nn as nn
import torch.nn.functional as func
# inplace=True,改变原始数据,默认False产生新的输入
m = nn.ReLU(inplace=True)
data = torch.tensor([-1, -3, -4, 0, 9, 4])
print(m(data))
print(data)
# 等价
print(func.relu(data))
输出: tensor([0, 0, 0, 0, 9, 4]) tensor([0, 0, 0, 0, 9, 4]) tensor([0, 0, 0, 0, 9, 4]) Process finished with exit code 0