2011/4/17 clodemil <[email protected]>:
> Hi all,
>
> # Measurements are taken three times in one session and entered in a
> continuous list "t":
>
> t=[ 151, 129, 126, 158, 163, 165, 150, 120, 147, 148, 134, 114, 180,
> 167, 159, 196, 175, 162, 135, 145, 135, 176, 172, 184, 149, 150, 152,
> 185, 185, 168, 143, 151, 142, 178, 172, 164, 147, 146, 142, 172, 166,
> 170, 163, 151, 149, 144, 147, 135, 146, 136, 142];
>
> # 3-tuples are isolated:
>
> m=matrix(ZZ,17,3,t);print m.str();
>
> # and put in a list of lists:
>
> z=list(m);z;
>
> # the mean of each session is calculated:
>
> for i in z:
>    u=n(mean(i),digits=3);
>    u
>
> # how can I get those into a list ?(so as to be able to zip it with a
> time list and plot)

one way to do it:

sage: zz = [n(mean(i),digits=3) for i in z]
sage: zz
[135., 162., 139., 132., 169., 178., 138., 177., 150., 179., 145.,
171., 145., 169., 154., 142., 141.]

another way:

sage: zz = map(lambda i: n(mean(i),digits=3), z)
sage: zz
[135., 162., 139., 132., 169., 178., 138., 177., 150., 179., 145.,
171., 145., 169., 154., 142., 141.]

or you could define a function that gets you the session averages
directly from t:

sage: def session_averages(t):
....:     return [n(mean((t[3*i],t[3*i+1],t[3*i+2])),digits=3) for i
in xrange(len(t)//3)]
....:
sage: session_averages(t)
[135., 162., 139., 132., 169., 178., 138., 177., 150., 179., 145.,
171., 145., 169., 154., 142., 141.]

-- 
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to