,可以通过以下步骤实现:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
local_maxima_indices = np.argrelextrema(y, np.greater)
local_maxima_values = y[local_maxima_indices]
max_value = np.max(local_maxima_values)
plt.plot(x, y)
plt.scatter(x[local_maxima_indices], local_maxima_values, color='red')
plt.show()
完整代码示例:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 10, 100)
y = np.sin(x)
local_maxima_indices = np.argrelextrema(y, np.greater)
local_maxima_values = y[local_maxima_indices]
max_value = np.max(local_maxima_values)
plt.plot(x, y)
plt.scatter(x[local_maxima_indices], local_maxima_values, color='red')
plt.show()
print("局部极大值的最大值:", max_value)
这段代码会生成一个包含局部极大值的正弦曲线图,并打印出局部极大值中的最大值。
推荐的腾讯云相关产品和产品介绍链接地址:
没有搜到相关的沙龙
领取专属 10元无门槛券
手把手带您无忧上云