scipy 的函数rv_histogram非常有用,如果我有一个经验分布,该分布由我想从中采样的直方图给出。因此,我可以对新数据进行采样,如下面的最小示例所示:import scipy.statsimport numpy as npimport matplotlib.pyplot as pltimport seaborn as snsimport pandas as pdx = np.array(range(2,8))hist_1d = pd.DataFrame(np.array([11., 46., 158., 75., 90., 14.]), index=x)plt.plot(x + 0.5, hist_1d.values)dist = scipy.stats.rv_histogram((hist_1d.values.ravel(), np.array(range(2,9))))plt.hist(dist.rvs(size=500), bins=len(x))现在我想对这个最小示例中给出的 2D 分布执行相同的操作:hist_2d = pd.DataFrame(np.array([[129, 162, 178, 182, 182, 182], [122, 163, 185, 191, 189, 185], [115, 164, 192, 200, 197, 189], [ 94, 136, 158, 162, 157, 152], [ 74, 108, 124, 125, 118, 116], [ 53, 80, 90, 88, 79, 80]]), index=range(2,8), columns=range(8,14))sns.heatmap(hist_2d)但是,rv_histogram函数认为只获取一维数据 - 或者至少我不知道如何传递两个 bin 边界向量。这可能吗,或者 Python 中是否有类似的功能?
添加回答
举报
0/150
提交
取消