4 ms·
The same author previously posted this code as a question on Stack Overflow: http://stackoverflow.com/questions/23295642/ http://stackoverflow.com/questions/232
by jzwinck 13y ago
The same author previously posted this code as a question on Stack Overflow: http://stackoverflow.com/questions/23295642/ http://stackoverflow.com/questions/23295642/ (but we didn't speed it up nearly as much as the Code Golf champions).
If you enjoyed this Python optimization, you may also enjoy: http://stackoverflow.com/questions/17529342/ http://stackoverflow.com/questions/17529342/
This sort of thing comes up a lot: people write mathematical code which is gratuitously inefficient, very often simply because they use a lot of loops, repeated computations, and improper data structures. So pretty much the same as any other language, plus the extra subtlety of knowing how and why to use NumPy (as it turned out, this was not a good time for it, though that was not obvious).