This series mainly features my personal experience on using Python in scientific research, where I introduce some unique and helpful usages of:
14 May 2019
When I first started doing research, I would try to use C++ to write my programs because of “performance concerns”. My instructor and facts soon made me realize that it is extremely inefficient to do so. I am starting to realize that in scientific research (especially for machine learning), Python almost always yields less total time consumption. The development time with Python is obviously less than that of C++ by magnitudes. But believe it or not, carefully written Python code can also run as fast as C/C++ code. Together with simple multithreading, serialization and graphing makes Python the ideal language for research. I am slowly changing my views towards Python from “an extremely slow and hard-to-read” language to “the best language ever if not for its relatively slower speed”.
14 May 2019
Unlike programming in C++, where loops are extremely efficient, the loops in Python are notoriously slow. Usually we need a lot of workarounds to eliminate loops in Python to achieve high performance. In my opinion, numpy can make loop unnecessary in at least 80 percent of scenarios. In this post, I demonstrate some common scenarios where proper numpy techniques can reduce the amount of code and improve performance. I would recommend that every time someone finds it necessary to write loops in Python for scientific computation, he/she should refer to the documentation of numpy/scipy or stackoverflow to see if there is built-in functions to help eliminate loops. Surprisingly, such functions usually exist (because we usually underestimate the number of APIs in numpy/scipy).
15 May 2019
The scipy package provides a variety of functionalities, which can be applied to a broad range of scientific research. It is quite common for us to ignore that fact that a function already exists in scipy and waste time on finding other packages or reinventing the wheels. In this post, I would show a series of applications for most scipy submodules, just to let readers get a grasp of how versatile this package is. Before the decision of writing one’s own code, it is always better to refer to scipy documentation and see if there is anything helpful.
17 May 2019
Sometimes scientific research has to do with a large number of repetitive experiments. In certain cases, the researcher has to adjust some key parameters of his/her application frequently. It may be inefficient to modify the code directly to do so, but it is also too demanding to write a special GUI for this scenario. Fortunately, matplotlib provides us with a concession, for it is able to generate simple interactive GUI with little effort. you can refer to the documentation of
matplotlib.widgets if you want to know more.
18 May 2019
Despite being lengthy and obscure, \(\LaTeX\) is still one of the most popular typesetting systems for academic literature. Fortunately, being a compiled (scripting) language, \(\LaTeX\) has a much larger room for customization, and it can do many things that WYSIWYG editors can only dream of. LuaTex is already a very unique and successful attempt to expose the low-level features of the \(\TeX\) compiler to a generic programming language. But due to the prevalence of pdflatex and xetex, I seldom use LuaTex.
27 Mar 2021
matplotlib is an extremely useful tool for scientific plotting. Many researchers use it to create plots for their publications. However, matplotlib uses Sans Serif fonts by default, which is rarely used in any scientific papers. As a result, if one inserts figures from matplotlib directly, it will end up with a different style compared to the paper. It is certainly not every aesthetic. In this post, I discuss my ways of tweaking matplotlib so that it generates high quality vector graphics that fits with your LaTeX paper.
A newer guide is available here.