在 numpy 中创建类似 'normal distribution' 的范围

Creating a 'normal distribution' like range in numpy

我正在尝试 'bin' 将一个数组放入 bin 中(类似于直方图)。我有一个输入数组 input_array 和一个范围 bins = np.linspace(-200, 200, 200)。整体功能如下所示:

def bin(arr):
    bins = np.linspace(-100, 100, 200)
    return np.histogram(arr, bins=bins)[0]

所以,

bin([64, 19, 120, 55, 56, 108, 16, 84, 120, 44, 104, 79, 116, 31, 44, 12, 35, 68])

会 return:

array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0])

但是,当我接近 0 时,我希望我的垃圾箱更多 'detailed'...类似于非交易正态分布。因此,当我接近 0 时,我可以有更多的箱子(即短距离),并且当我向范围移动时,箱子更大。可能吗?

更具体地说,不是在一个范围内有同样宽的 bin,而是我可以有一个范围数组,其中朝向中心的 bin 小于朝向极端的 bin 吗?

我已经看过 this and numpy.random.normal 之类的答案,但点击不正确。

使用反误差函数生成 bin。您需要缩放垃圾箱以获得您想要的确切范围

此转换有效,因为逆误差函数在零附近比在 +/- 1 附近更平坦。

from scipy.special import erfinv
erfinv(np.linspace(-1,1))
# returns: 
array([       -inf, -1.14541135, -0.8853822 , -0.70933273, -0.56893556,
       -0.44805114, -0.3390617 , -0.23761485, -0.14085661, -0.0466774 ,
        0.0466774 ,  0.14085661,  0.23761485,  0.3390617 ,  0.44805114,
        0.56893556,  0.70933273,  0.8853822 ,  1.14541135,         inf])