Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Looking for module for shrinking a list with n-point means

Reply
Thread Tools

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

 
 
Yash Ganthe
Guest
Posts: n/a
 
      05-22-2009
Hi,

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 SciPy or NumPy or any other module have functions for achieving
this?

Which function can be used for doing this?

Thanks,
Yash
 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      05-22-2009
On May 22, 8:03*pm, Yash Ganthe <yas...@gmail.com> wrote:
> Hi,
>
> 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 SciPy or NumPy


What do their docs say?


> or any other module have functions for achieving
> this?
>
> Which function can be used for doing this?


Perhaps one like this:

| >>> def n_point_means(alist, n):
| ... blist = alist[:]
| ... blist.sort()
| ... size = len(blist)
| ... assert 1 <= n <= size
| ... assert size % n == 0
| ... clist = []
| ... fn = float(n)
| ... for i in xrange(0, size, n):
| ... clist.append(sum(blist[i:i+n]) / fn)
| ... return clist
| ...
| >>> aaa = [9,8,7,6,5,4,3,2,0]
| >>> n_point_means(aaa,2)
| Traceback (most recent call last):
| File "<stdin>", line 1, in <module>
| File "<stdin>", line 6, in n_point_means
| AssertionError
| >>> aaa = [9,8,7,6,5,4,3,2,1,0]
| >>> n_point_means(aaa,2)
| [0.5, 2.5, 4.5, 6.5, 8.5]
| >>> n_point_means(aaa,5)
| [2.0, 7.0]
| >>>

Does that do what you want? If your requirement is so simple, why not
write it yourself?

 
Reply With Quote
 
 
 
 
Robert Kern
Guest
Posts: n/a
 
      05-22-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(12
> v.shape = (16,
> 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

 
Reply With Quote
 
Yash Ganthe
Guest
Posts: n/a
 
      05-23-2009
Thanks John,

The code u provided works for me. Indeed it is a simple requirement
and I am a complete novice to Python.

-Yash
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shrinking icons Roedy Green Java 3 01-30-2006 08:42 AM
2503 & shrinking processor memory Christoph Gartmann Cisco 13 12-03-2005 03:11 PM
Web page width is shrinking/scrunching on some machines Eric ASP .Net 4 06-30-2004 03:18 PM
Screen shrinking Palmira Vicks Computer Support 11 01-03-2004 02:17 PM
w98se - manual registry shrinking Greg M Computer Support 8 12-09-2003 07:58 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57