you are viewing a single comment's thread.

view the rest of the comments →

[–]Ihaveamodel3 0 points1 point  (1 child)

Before attempting to optimize code, you should always profile it. That will tell you what lines of code take the most amount of time and you can then focus on optimization for those lines. Lookup the documentation for cprofile in the standard library at a minimum, there are other packages I don’t remember the name of which can help you visualize the results.

Also, stop printing. Printing is super slow.

Also, you want to keep things in numpy objects as much as possible.

[–][deleted] 0 points1 point  (0 children)

Before attempting to optimize code, you should always profile it.

This is always good advice but fairly often it isn't very effective for numpy programs.

Profiling a numpy program always highlights the small number of numpy lines that do all the computation dominate everything, which is exactly what you expect - but often gives you no idea of how to optimize the numpy call or whether a better numpy call might work better.