I think you are right, it's the assignment itself which is slow.
Merged loop is only a tad quicker.

On Thursday, September 8, 2016 at 6:04:41 PM UTC+1, Christian Gollwitzer wrote:
> > Why nested loops are so slow in Python? Is it because new contexts are 
> > created?
> > For more details, see
> > http://stackoverflow.com/questions/26611043/numpy-vs-cython-nested-loop-so-slow
> > http://stackoverflow.com/questions/39371021/efficient-loop-over-numpy-array
> 
> The answers are right there, too - what are you mising? CPython is an 
> interpreter. For every seemingly simple operation like a[i]=j, a 
> function pointer is called, the variables contain polymorphic types 
> which are morphed, etc. The same thing in compiled code is a single 
> machine instruction. Speed differences of ~100x are normal between 
> compiled and interpreted code over all dynamic languages.
> 
>       Christian

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

Reply via email to