problem with array and for loop

Robert Kern robert.kern at gmail.com
Thu May 11 01:52:03 EDT 2006


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.

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

-- 
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