flebber wrote:

> Thank you for the replies.
> 
> Looking at the replies I am wondering which solution is more scalable. At
> the moment it is only 2 nested lists but what about 5, 10, 20 or more?
> 
> Should I start looking into numpy to handle this or will list
> comprehension
>   >>> [ [ x + y for x, y in zip(x,y) ] for x, y in zip(a,b) ]
> Be sufficient ?

I would certainly prefer

>>> a + b
array([[ 6,  8],
       [10, 12]])

over the incomprehensible comprehension. But if it is the only usecase for 
numpy in your script and you are OK with its current performance, just put 
your listcomp into an aptly named function. Then you can write the easily 
understandable

c = matrix_add(a, b)

and avoid the numpy dependency. 

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to