There are two outputs to numpy.histogram
:
hist
: values of the histogrambin_edges
: Return the bin edges(length(hist)+1)
both are vectors but in the example below, the second vector is of length 101, which is 1 higher than the first vector, which is length 100 :
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)
The following shape error occurs if I then try plt.plot(bins1,a)
:
ValueError: x and y must have same first dimension, but have shapes (101,) and (100,)
Why, and how do I fix the inequal shape error so I can plot the histogram?