【问题标题】:Getting an arrays of equal length from numpy histogram or plotting the uneven array从 numpy 直方图中获取长度相等的数组或绘制不均匀数组
【发布时间】:2015-06-30 23:01:53
【问题描述】:

这可能是一个简单的问题,但我想不通。

假设我有一个这样的数据集:

180.0
170.9
-180.0
0.00
50.0
...

我一直在使用 numpy.histogram 函数来获取 -180 到 180 范围内的概率值

probs, ang = np.histogram(angles, bins=360, range=(-180,180))

但是它返回一个长度不等的 hist 数组和 bin_edges 数组

返回:

历史:数组

直方图的值。有关可能语义的描述,请参见 normed 和 weights。

bin_edges : dtype 浮点数组

返回 bin 边缘 (length(hist)+1)。

如何获得我的数据集的概率,其中我的范围内的每个数字(-180 到 180,包括零)都具有与之相关的概率,例如:

range prob
-180  0.70
-170  0.01
-160  0.01

我需要概率与范围匹配

我是这样在matlab中做的

[probas, angles] = hist(x, -180:10:180, 1.0);

这看起来很相似,但不起作用。

【问题讨论】:

    标签: python matlab numpy histogram probability


    【解决方案1】:

    垃圾箱已经等间距了。

    要从直方图中获取概率,您必须进行归一化(即除以所有直方图值的总和):

    probs = probs / np.sum(probs)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-14
      • 2020-09-25
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多