直接上代码

import torch
import matplotlib.pyplot as plt

A = torch.arange(-10, 10, 1, dtype=torch.float(32))
def relu(x):
	return torch.maximum(torch.tensor(0), x)
plt.plot(relu(A))

结果如下:
机器学习 - 手动实现 ReLU 和 Sigmoid-LMLPHP

import torch
import matplotlib.pyplot as plt

A = torch.arange(-10, 10, 1, dtype=torch.float(32))
def sigmoid(x):
	return 1 / (1 + torch.exp(-x))
	
plt.plot(sigmoid(A))

机器学习 - 手动实现 ReLU 和 Sigmoid-LMLPHP

03-30 02:57