# -*- coding: utf-8 -*-
import numpy as np
x = np.array([-1,1,2])
y = x>0
print(y)
print(y.astype(np.int))
#阶跃函数图像
import matplotlib.pyplot as plt
def step_function(x):
return np.array(x>0,dtype = np.int)
x = np.arange(-5,5,0.1)
y = step_function(x)
#sigmoid函数
def sigmoid(x):
return 1/(1+np.exp(-x))
x2 = np.arange(-5,5,0.1)
y2 = sigmoid(x)
plt.plot(x,y,x2,y2)
plt.ylim(-0.1,1.1)
plt.show()
输出结果
[False True True]
[0 1 1]