Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 创建一个';正态分布';喜欢在numpy的范围_Python_Numpy_Normal Distribution - Fatal编程技术网

Python 创建一个';正态分布';喜欢在numpy的范围

Python 创建一个';正态分布';喜欢在numpy的范围,python,numpy,normal-distribution,Python,Numpy,Normal Distribution,我正在尝试将数组“装箱”到箱子中(类似于直方图)。我有一个输入数组input\u数组和一个范围bins=np.linspace(-200200200200)。整体功能如下所示: def bin(arr): bins = np.linspace(-100, 100, 200) return np.histogram(arr, bins=bins)[0] 所以 将返回: array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

我正在尝试将数组“装箱”到箱子中(类似于直方图)。我有一个输入数组
input\u数组
和一个范围
bins=np.linspace(-200200200200)
。整体功能如下所示:

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

将返回:

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时,我希望我的垃圾箱更加“详细”。。。类似于指数正态分布的东西。因此,当我接近0时,我可能会有更多的箱子(即短距离),当我向该范围移动时,箱子会更大。可能吗

更具体地说,与其在一个范围内有同样宽的垃圾箱,我可以有一个朝向中心的垃圾箱比朝向极端的垃圾箱小的范围阵列吗


我已经看过了像和这样的答案,但是有些东西没有点击右键。

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

此转换之所以有效,是因为逆误差函数在0附近比+/-1更平坦


np.histogram
确实支持非均匀的箱子宽度,所以您想要的肯定是可能的。不过,你到底想如何设置垃圾箱的宽度?@Nathan我越接近0,垃圾箱就越小-以一种类似于正态分布的方式-清楚吗?
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])
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])