[Tutor] IndexError: index out of bounds

Walter Prins wprins at gmail.com
Wed Mar 27 17:14:03 CET 2013


Hi,


On 27 March 2013 15:50, Sayan Chatterjee <sayanchatterjee at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20130327/69571bb0/attachment.html>


More information about the Tutor mailing list