X
PrevPrev Go to previous topic
NextNext Go to next topic
Last Post 13 Mar 2015 06:03 AM by  anon
histogram function problem...
 1 Replies
Sort:
You are not authorized to post a reply.
Author Messages

anon



New Member


Posts:
New Member


--
13 Mar 2015 06:03 AM
    http://www.idlcoyote.com/math_tips/ra... for example x = [-0.5d, -0.45d, -0.4d, -0.35d, -0.3d, -0.25d] ; this should be a uniform distribution h = histogram(x, binsize=0.05d, loc=loc, min=-0.5d, max=-0.25d) but h is strange result!! print, h;; [2 1 0 1 1 1] but 'x' and 'loc' equal!! print, array_equal(x, h) but python numpy.histogram is good import numpy as np x = [-5.50,-5.45,-5.40,-5.35,-5.30,-5.25] h, loc = np.histogram(x, bins=6, range=[-5.5, -5.2]) pirnt h Is there a fundamental solution is to improve the histogram function?? thanks

    Zachary Norman



    Basic Member


    Posts:173
    Basic Member


    --
    03 Apr 2015 10:40 AM
    Hello, The error came from the bins starting at the same locations that the points were at. Try this code and see the difference: x = [-0.5, -0.45, -0.4, -0.35, -0.3, -0.25] density= histogram(x, binsize=0.05, loc=loc, min=-0.50001, max=-0.25) print, loc ;loc is the start of the bins x2 = [-0.5, -0.45, -0.4, -0.35, -0.3, -0.25] density2= histogram(x, binsize=0.05, loc=loc, min=-0.5, max=-0.25) b1 = barplot(x,density, title = 'fixed bin size') b1 = barplot(x2,density2,title = 'broken bin size')
    You are not authorized to post a reply.