Re: [Tutor] initialising all elements of a matrix

2012-02-28 Thread Peter Otten
bob gailer wrote: > On 2/28/2012 11:40 AM, Peter Otten wrote: > > def product(factors, product=1): > for factor in factors: > product *= factor > return product > > can be "simplified" > > def product(factors): >import operator >return reduce(operator.mul, factors) I

Re: [Tutor] initialising all elements of a matrix

2012-02-28 Thread bob gailer
On 2/28/2012 11:40 AM, Peter Otten wrote: def product(factors, product=1): for factor in factors: product *= factor return product can be "simplified" def product(factors): import operator return reduce(operator.mul, factors) -- Bob Gailer 919-636-4239 Chapel Hill NC _

Re: [Tutor] initialising all elements of a matrix

2012-02-28 Thread Peter Otten
Sivaram Neelakantan wrote: > > I was wondering whether there is a faster/better/cleaner way of > element wise operations of arbitrarily nested list. I wrote something > like this for 1 level nested lists and am wondering whether there are > any good idioms in python. I did this after a ridiculo

[Tutor] initialising all elements of a matrix

2012-02-28 Thread Sivaram Neelakantan
I was wondering whether there is a faster/better/cleaner way of element wise operations of arbitrarily nested list. I wrote something like this for 1 level nested lists and am wondering whether there are any good idioms in python. I did this after a ridiculous amount of bad thinking/missteps in