quickly looping over a 2D array?

Peter Otten __peter__ at web.de
Mon Jul 27 07:42:48 EDT 2009


Martin wrote:

> I am new to python and I was wondering if there was a way to speed up
> the way I index 2D arrays when I need to check two arrays
> simultaneously? My current implementations is (using numpy) something
> like the following...
> 
> for i in range(numrows):
>     for j in range(numcols):
> 
>         if array_1[i, j] == some_value or array_2[i, j] >= array_1[i,
> j] * some_other_value
>             array_1[i, j] = some_new_value

array_1[(array_1 == some_value) | (array_2 >= array_1 * some_other_value)] = 
some_new_value

maybe?




More information about the Python-list mailing list