I have a numpy array of values that I want to divide into bins of equal frequencies.
x = np.array([5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5])
I have tried using the below solution based on the existing solution, however in order to get the number of bins and frequency of value in each bins, I have to use plt.hist
which results in graph plot that I donot want to plot. I just need the count of values in bins, the number of bins.
def histedges_equalN(x, nbin):
npt = len(x)
return np.interp(np.linspace(0, npt, nbin + 1),
np.arange(npt),
np.sort(x))
x = np.random.randn(1000)
n, bins, patches = plt.hist(x, histedges_equalN(x, 10))
So, how can I get the n, bins without using plt.hist
? Is there any alternative method ?