loop? maybe?

Mike Driscoll kyosohma at gmail.com
Fri Apr 10 17:29:58 CEST 2009


On Apr 10, 7:42 am, heidi taynton <heidihan... at mac.com> wrote:
> Hey guys,
>
> Sorry for being such a noob with this stuff and the language is hard for me to read through with the online manuals...  i can do math speak, and science speak... not so much programming/code speak... so when you say pickle... i think food....
>
> Anyways,
>
> I have an array and I want to turn it into a new array.   where
>
> nlines = 188
> new_array=n.array(nlines)
>
> for i in arange(nlines):
>
> #####   and here i want to tell it to read old_array and take  n  data points  where new_n=1.1**old_n ... take the mean of those data points and put them in the first spot in the array....    then loop through with until the array is full?      If it doesn't make sense, i can try to clarify some more...
>
> Thanks, you guys are life savers,
> hi

I'm probably missing something, but is this sort of what you are
looking for?

<code>

nlines = 188
new_array = [] # this creates a list
for i in range(nlines):
    new_n = 1.1 ** i
    mean = (new_n + i) / 2
    new_array.append(mean)

</code>

If you wanted a cumulative mean of the values, then you'll have to
change it slightly of course, probably by using a nested loop.

Hopefully this isn't a homework question, but even if it is, it's an
interesting exercise.

Mike



More information about the Python-list mailing list