OSError
Flask项目
python filename.py
报错
地址已被使用
搜索相关问题后发现是因为,你曾启动过相同或者类似的服务占用了这个端口(一般来讲,在Mac上直接用Python启动的话,会导致退出不完整,你不能通过点击GUI的“退出”按钮来一步到位,后台的Python进程还是存在的,而它就是一直占用端口不释放的元凶)
Solution
- 改掉默认的端口
只能解决当前的问题,后续仍会出现类似的问题 - 就是杀掉占用端口的程序
使用lsof命令
,全写是list open file
,可以列出当前系统打开文件
我们要找到之前占用的端口5000
所以终端输入的命令为:
lsof -i:5000
然后可以看到PID为9108
- 接下来杀掉这个进程就可以了
在终端输入命令:
kill 9108
之后重新运行下程序就不会报错了
np.degress()
将弧度转换为角度
np.pi ----> number
import numpy as np
angle = np.array([np.pi/2, np.pi/3, np.pi/6])
np.degrees(angle)
scipy.signal.argrelextrema
求数组中的极大值和极小值
peaks
signal.argrelextrema(data_y, np.greater, order=1)
valleys
valley_indexes = signal.argrelextrema(data_y, np.less, order=1)
Param
- data_y: plot的竖直value 或 data
- np.greater: 极大
- np.less: 极小
- order: 两侧用多少点进行比较
from scipy import signal
import numpy as np
import matplotlib.pyplot as plt
data_x = np.arange(start = 0, stop = 40, step = 1, dtype='int')
data_y = np.array([98,96,97,100,95,105,75,50,45,42,
51,85,90,92,91,89,101,62,65,52,
47,58,55,75,89,92,94,91,89,79,
85,65,42,55,48,50,85,88,95,100])
# Find peaks
# order:两侧使用多少点进行比较
peak_indexes = signal.argrelextrema(data_y, np.greater, order=1)
peak_indexes = peak_indexes[0]
# Find valleys
# order:两侧使用多少点进行比较
valley_indexes = signal.argrelextrema(data_y, np.less, order=1)
valley_indexes = valley_indexes[0]
(fig, ax) = plt.subplots()
# Plot all data
ax.plot(data_x, data_y)
# Plot peaks
peak_x = peak_indexes
peak_y = data_y[peak_indexes]
ax.scatter(peak_x, peak_y, marker='o', color='red', label="Peaks")
# Plot valleys
valley_x = valley_indexes
valley_y = data_y[valley_indexes]
ax.scatter(valley_x, valley_y, marker='o', color='green', label="Valleys")
# 添加标题
plt.title('Find peaks and valleys using argrelextrema()')
# 添加图例
plt.legend(loc='best')
# 保存图像
plt.savefig('peaks-valleys.png')
# 显示图像
plt.show()
set Param
order = 1
order = 3