dev*_*ist 6 python numpy matplotlib histogram binning
有两个输出numpy.histogram:
hist:直方图的值bin_edges:返回 bin 边缘(length(hist)+1)两者都是向量,但在下面的示例中,第二个向量的长度为 101,比第一个向量(长度为 100)高 1:
import numpy as np
from numpy.random import rand, randn
n = 100 # number of bins
X = randn(n)*.1
a,bins1 = np.histogram(X,bins=n)
Run Code Online (Sandbox Code Playgroud)
如果我随后尝试,则会出现以下形状错误plt.plot(bins1,a):
ValueError: x and y must have same first dimension, but have shapes (101,) and (100,)
为什么以及如何修复不等形状错误以便绘制直方图?
| 归档时间: |
|
| 查看次数: |
2625 次 |
| 最近记录: |