地址已被使用
搜索相关问题后发现是因为,你曾启动过相同或者类似的服务占用了这个端口(一般来讲,在Mac上直接用Python启动的话,会导致退出不完整,你不能通过点击GUI的“退出”按钮来一步到位,后台的Python进程还是存在的,而它就是一直占用端口不释放的元凶)
lsof命令
,全写是list open file
,可以列出当前系统打开文件我们要找到之前占用的端口5000
所以终端输入的命令为:
lsof -i:5000
然后可以看到PID为9108
kill 9108
之后重新运行下程序就不会报错了
将弧度转换为角度
np.pi ----> number
import numpy as np
angle = np.array([np.pi/2, np.pi/3, np.pi/6])
np.degrees(angle)
求数组中的极大值和极小值
signal.argrelextrema(data_y, np.greater, order=1)
valley_indexes = signal.argrelextrema(data_y, np.less, order=1)
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()