【发布时间】:2022-01-16 17:43:32
【问题描述】:
我有一个连续输入函数,我想将其离散化为 5-10 个介于 1 和 0 之间的离散箱。现在我正在使用 np.digitize 并将输出箱重新调整为 0-1。现在的问题是,有时数据集(蓝线)会产生如下结果:
我尝试增加离散化箱的数量,但最终保持了相同的噪声并获得了更多的增量。作为算法使用相同设置但另一个数据集的示例:
这是我在那里使用的代码 NumOfDisc = 箱数
intervals = np.linspace(0,1,NumOfDisc)
discretized_Array = np.digitize(Continuous_Array, intervals)
图中的红色线并不重要。连续的蓝线是我尝试离散化的,绿线是离散化的结果。使用以下代码使用 matplotlyib.pyplot 创建图表:
def CheckPlots(discretized_Array, Continuous_Array, Temperature, time, PlotName)
logging.info("Plotting...")
#Setting Axis properties and titles
fig, ax = plt.subplots(1, 1)
ax.set_title(PlotName)
ax.set_ylabel('Temperature [°C]')
ax.set_ylim(40, 110)
ax.set_xlabel('Time [s]')
ax.grid(b=True, which="both")
ax2=ax.twinx()
ax2.set_ylabel('DC Power [%]')
ax2.set_ylim(-1.5,3.5)
#Plotting stuff
ax.plot(time, Temperature, label= "Input Temperature", color = '#c70e04')
ax2.plot(time, Continuous_Array, label= "Continuous Power", color = '#040ec7')
ax2.plot(time, discretized_Array, label= "Discrete Power", color = '#539600')
fig.legend(loc = "upper left", bbox_to_anchor=(0,1), bbox_transform=ax.transAxes)
logging.info("Done!")
logging.info("---")
return
任何想法我可以做些什么来获得像第二种情况那样的合理离散化?
【问题讨论】:
-
您能添加一个最小的可重现问题吗?
-
非常抱歉,但我不明白你的意思
-
没问题,您能否添加一段代码,您可以复制粘贴以获取您在此处显示的图表?这样其他人就更容易尝试和使用它
-
我更新了问题。现在好点了吗?
-
请注意,在发帖之前您应该知道minimal reproducible example 是什么。
标签: python numpy discretization