p_za = [None]*N is not giving away the error message. for i in range(0,N): p_za.append = p_initial[i] + t*K*cos(K*p_initial[i]); is also not working.
Could you please redirect me to a link where the example is demonstrated? What is the simplest way to assign an array element a value? i.e the C analogue of: int array[200] for(i=0;i<200;i++) array[i] = 2*i + 5; On 27 March 2013 21:44, Walter Prins <wpr...@gmail.com> wrote: > Hi, > > > On 27 March 2013 15:50, Sayan Chatterjee <sayanchatter...@gmail.com>wrote: > >> Dear all, >> >> When trying to print or assign array elements, getting the following >> error: >> >> Traceback (most recent call last): >> File "ZA.py", line 32, in <module> >> p_za[i] = p_initial[i] + t*K*cos(K*p_initial[i]); >> IndexError: index out of bounds >> >> I am using Numpy, is it due to that? I am attaching the code herewith. >> > > Not Numpy no. The p_za list appears to be empty at the point where the > above assgnment to p_za[i] is done, hence you get the "IndexError" message. > You should initialise p_za to be as long as needed first. Maybe by simply > using p_za = [None] * N instead of assigning [], or alternately perhaps by > appending instead at the point where you first reference p_ze[i]. > > Walter > > > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > -- -------------------------------------------------------------------------- *Sayan Chatterjee* Dept. of Physics and Meteorology IIT Kharagpur Lal Bahadur Shastry Hall of Residence Room AB 205 Mob: +91 9874513565 blog: www.blissprofound.blogspot.com Volunteer , Padakshep www.padakshep.org
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor