绘制下列函数图形 1. def step_function(x): return np.array(x > 0, dtype=np.int) 2. def sigmoid(x): return 1 / (1 + np.exp(-x))
时间: 2024-04-28 17:19:03 浏览: 144
绘制函数图像
5星 · 资源好评率100%
好的,下面是两个函数的图形:
1. `step_function`
```python
import numpy as np
import matplotlib.pyplot as plt
def step_function(x):
return np.array(x > 0, dtype=np.int)
x = np.linspace(-5, 5, 100)
y = step_function(x)
plt.plot(x, y)
plt.title('Step Function')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
```
![step_function](https://i.imgur.com/zgK9S1S.png)
2. `sigmoid`
```python
import numpy as np
import matplotlib.pyplot as plt
def sigmoid(x):
return 1 / (1 + np.exp(-x))
x = np.linspace(-5, 5, 100)
y = sigmoid(x)
plt.plot(x, y)
plt.title('Sigmoid Function')
plt.xlabel('x')
plt.ylabel('y')
plt.show()
```
![sigmoid](https://i.imgur.com/qXw5e7F.png)
阅读全文