Numpy Histogram Representing Floats With Approximate Values As The Same
I have code that generates a certain value from -10 to 10 given a range from [0,1) The code takes the value from -10 to 10 and it will append it to a list, according to its probabi
Solution 1:
I think the underlying issue is that your bin size is uniform, whereas the differences between the unique values in pos
scale exponentially. Because of that you'll always end up either with weird 'spikes' where two nearby unique values fall within the same bin, or lots of empty bins (especially if you just increase the bin count to get rid of the 'spikes').
You could try setting your bins according to the actual unique values in pos
, so that their widths are non-uniform:
# the " + [10,]" forces the rightmost bin edge to == 10
uvals = np.unique(pos+[10,])
hist, bins = np.histogram(pos,bins=uvals)
plt.bar(bins[:-1],hist,width=np.diff(bins))
Baca Juga
Solution 2:
I believe you're fine. I reran your code using bins = 200
instead of bins = 100
and the spikes disappeared. I think you had values that got caught on the boundaries between bins.
Post a Comment for "Numpy Histogram Representing Floats With Approximate Values As The Same"