将数组转换为分布的更简单方法?

Easier way to transform array into a distribution?

我有一个数组 vox_betas,它包含 21600 个浮点数(范围从 ~0 到 ~2),当按数组特征排序时,你可以看到数据有一个结构(见第一张图片)。

我想要一个反映这种结构的数组——本质上我想调用 sns.distplot() 并让它产生与第一张图片相同的情节。现在sns.distplot(vox_betas)描绘了第二张图,这不是我想要的。

我能够在第三张图片中通过创建数组 dist 来完成此操作,但是我完成此操作的方式很草率,甚至丢失了一些信息(我的代码在下面)。

如何将 vox_betas 和特征转换为 dist?有人有什么想法吗?

plt.scatter(features,vox_betas)

sns.distplot(vox_betas)

dist=[]
for f in np.unique(features):
    dist = np.concatenate((dist,
                np.repeat(f,
                np.sum(
                [vox_betas[j]*10 for j in np.where(features==f)[0]]))))

sns.distplot(dist)

这叫做inverse transform sampling:

is a basic method for pseudo-random number sampling, i.e., for generating sample numbers at random from any probability distribution given its cumulative distribution function.

我找到的最佳解释是 this one. Also discussed here