Looking for module for shrinking a list with n-point means

Robert Kern robert.kern at gmail.com
Fri May 22 15:06:44 EDT 2009


On 2009-05-22 08:50, Scott David Daniels wrote:
> Yash Ganthe wrote:
>> I would like to shrink a large list in the following way:
>> If the List has 1000 integers, we need only 100 averages such that the
>> 1000 points are average for every 10 consecutive values. So p0 to p9
>> will be averaged to obtain t0. p10 to p19 will be averaged to obtain
>> t1 and so on. This is a 10-point mean.
>>
>> We are doing this as we collect a lot of data and plot it on a graph.
>> Too many samples makes the graph cluttered. So we need to reduce the
>> number of values in the way described above.
>
> Does this give you a clue?
>
> import numpy as np
>
> v = np.arange(128)
> v.shape = (16, 8)
> sum(v.transpose()) / 8.

Or even:

import numpy as np

v = np.arange(1000).reshape((-1, 10))
ten_point_mean = v.mean(axis=1)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco




More information about the Python-list mailing list