Why is my computation so much faster in C# than Python

后端 未结 6 1644
日久生厌
日久生厌 2020-12-07 21:40

Below is a simple piece of process coded in C# and Python respectively (for those of you curious about the process, it\'s the solution for Problem

6条回答
  •  攒了一身酷
    2020-12-07 21:57

    Python (and all scripting languages including matlab) is not intended to be directedly used for large-scale numerical calculation. To have a compatible result as complied programs, avoid the loops at all cost and convert the formula to matrix formats (that needs a little mathematical understanding and skill), so that we can push as much as possible to the background C library provided by numpy, scipy, etc.

    Again, DO NOT write loops for numerical calculation in python, whenever a matrix equivalent possible!

提交回复
热议问题