<p dir="ltr"><br>
On 5 Jul 2013 11:58, "Helmut Jarausch" <<a href="mailto:jarausch@igpm.rwth-aachen.de">jarausch@igpm.rwth-aachen.de</a>> wrote:<br>
><br>
> On Fri, 05 Jul 2013 11:13:33 +0100, Oscar Benjamin wrote:<br>
><br>
> > My one comment is that you're not really making the most out of numpy<br>
> > arrays. Numpy's ndarrays are efficient when each line of Python code<br>
> > is triggering a large number of numerical computations performed over<br>
> > the array. Because of their N-dimensional nature and the fact that<br>
> > they are in some sense second class citizens in CPython they are often<br>
> > not as good as lists for this kind of looping and indexing.<br>
> ><br>
> > I would actually expect this program to run faster with ordinary<br>
> > Python lists and lists of lists. It means that you need to change e.g.<br>
> > Grid[r, c] to Grid[r][c] but really I think that the indexing syntax<br>
> > is all you're getting out of numpy here.<br>
> ><br>
><br>
> Thanks Oscar, that was a big improvement, indeed.<br>
> Using lists of lists instead of numpy arrays made the code more than<br>
> twice as fast (13 seconds down to 6 seconds)<br>
><br>
> Since I don't do any numerical stuff with the arrays, Numpy doesn't seem to be<br>
> a good choice. I think this is an argument to add real arrays to Python.<br>
><br>
> I even tried to use dictionaries instead of Numpy arrays. This version is a bit<br>
> slower then the lists of lists version (7.2 seconds instead of 6 second) but still<br>
> much faster than the Numpy array solution.</p>
<p dir="ltr">May I suggest you avoid range and use enumerate(the_array) instead? It might be faster.</p>