I have set of value in float (always less than 0). Which I want to bin into histogram,
i,e. each bar in histogram contain range of value [0,0.150)

The data I have looks like this:

0.000
0.005
0.124
0.000
0.004
0.000
0.111
0.112


Whith my code below I expect to get result that looks like

[0, 0.005) 5
[0.005, 0.011) 0
...etc..


I tried to do do such binning with this code of mine.
But it doesn't seem to work. What's the right way to do it?

#! /usr/bin/env python


import fileinput, math

log2 = math.log(2)

def getBin(x):
    return int(math.log(x+1)/log2)

diffCounts = [0] * 5

for line in fileinput.input():
    words = line.split()
    diff = float(words[0]) * 1000;

    diffCounts[ str(getBin(diff)) ] += 1

maxdiff = [i for i, c in enumerate(diffCounts) if c &gt; 0][-1]
print maxdiff
maxBin = max(maxdiff)


for i in range(maxBin+1):
     lo = 2**i - 1
     hi = 2**(i+1) - 1
     binStr = '[' + str(lo) + ',' + str(hi) + ')'
     print binStr + '\t' + '\t'.join(map(str, (diffCounts[i])))


~                                                                   


Question: why wavelet is more suitable for image compression compared to DCT?
Answer: Both JPEG and JPEG 2000 use the change of basis compression type.

Namely, we transform the data into a different representation assuming in this representation the number of parameters needed to describe to data is lower.
Or to the least, most of the information is gathered within few parameters.

Now, if you look at the energy level of the DCT coefficients of real world images you'd see most of the energy is limited to the very few coefficients.
This is what JPG does, keeps only the few dominant coefficients and throws the rest.

How efficient is DCT?
It depends on how less coefficients are needed to describe the image in an acceptable quality.

It turns out that for Wavelets the situation is better.
Namely on real world images less coefficients are needed to describe the image with the same perceived quality.

This property is called the ability to decorrelate the data / being energy densed, etc...

At the end, it is all up to how much less parameters are needed to describe the same data.

P.S.
Using SVD / KLT (They are equivalent in this sense) would be even more efficient in the sense of how much less coefficients are needed for the same quality (In the $ {\ell}_{2} $ sense).
The problem is those bases are adaptive to the data and hence if you use them you have to include them to be able to decompress the data.
What's so nice, you can ask which, in general, approximate the SVD better?
It turns out that Wavelets are better doing so.