problem with array and for loop

Fabian Braennstroem f.braennstroem at gmx.de
Thu May 11 02:20:23 EDT 2006


Hi Robert,

* Robert Kern <robert.kern at gmail.com> wrote:
> Fabian Braennstroem wrote:
>> Hi,
>> 
>> I have a 'simple' problem with a multidimension array in a
>> for loop. It looks like this:
>> 
>> wert= zeros([127,2])
>> wert1= zeros(127)
>> m=1
>> l=1
>> 
>> for pos in [pos1,pos2,pos3]: 
>>     for i in range(1,125):
>>         wert[l,m]= probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i);
>> #        wert1[i]= probe1.GetOutput().GetPointData().GetScalars().GetTuple1(i);
>>         m=m+1;
>>     l=l+1;
>> 
>> It works for the 1D 'wert1'. Does anyone have an idea? 
>
> Oy vey.
>
> So the first time through, you are setting the second column of wert. Then l
> (btw, never, ever use lower-case "l" as a single-letter variable name; it looks
> like "1") gets incremented to 2, which would try to put data into the third
> column of wert. However, wert only has two columns.

Thanks! I misunderstood the declaration of a multid-dim
array; it works now.
>
> Are you aware that numpy array indices start with 0, not 1?
>
> You will probably want to ask numpy questions on the numpy-discussion mailing list:
>
>   http://www.scipy.org/Mailing_Lists

I thought a simple for loop-array-declaration question would
fit in this group ... it actually help for this simple
problem. Thanks!

Greetings!
 Fabian




More information about the Python-list mailing list