If you want to use numpy
, you can use numpy.histogram:
>>> import numpy as np
>>> x, y = np.loadtxt('data.txt', unpack=True)
>>> bins = np.arange(10+1)
>>> totals, edges = np.histogram(x, weights=y, bins=bins)
>>> totals
array([ 324., 1578., 227., 0., 0., 0., 0., 0.,
0., 0.])
This gives the total in each bin, and you could divide by the width of the bin to get an approximate instantaneous rate:
>>> totals/np.diff(bins)
array([ 324., 1578., 227., 0., 0., 0., 0., 0.,
0., 0.])
(Okay, since the bin widths were all one, that isn't very interesting.)
[update]
I'm not sure I understand your follow-up comment that you need the average packet size in each second -- I don't see that mentioned anywhere in your question, but I'm notorious at missing the obvious.. :-/ In any case, if you want the number of packets in a time bin, then you simply don't need to set the weights (default is 1):
>>> counts, edges = np.histogram(x, bins=bins)
>>> counts
array([4, 6, 3, 0, 0, 0, 0, 0, 0, 0])
where counts is the number of packets which arrived in each bin.