Introduction to Scientific Python#

Download all chapters as JupyterLab notebooks

The use of computers in everyday life cannot be understated. From the first instants of the day to the final moments before sleep, we are surrounded by appliances and technologies that have some sort of computing mechanism attached to them. While the word “computers” is a much broader term these days when compared to before the early 2000s (i.e., computers often meant a standalone device dedicated for some computing need, e.g., a computer tower), the advent of mobile phones, internet of things (IoT) devices, and “smart” appliances have led to a diversification on what a computer is and can be.

Our dependence on computers extends to professional endeavors, including the fields of science and engineering. Even simple internet searches on how computing technologies have impacted these fields leads to an overwhelming number of examples. From controlling measurement and processing equipment, analyzing datasets, creating impactful figures and tables, modeling real world phenomena, and solving complex systems using machine learning, our dependency on and benefit from computing devices continues to increase yearly. As these examples highlight, it is important that engineers learn how to program computing devices to solve problems. While full mastery of computer programming is often left to the computer science discipline, this field does not focus on the fundamental physical phenomena that govern many engineering applications. Engineers with computer programming skills can act as “knowledge bridges” that connect numerical results generated by computational experts to physical phenomena. It is now more important than ever for engineers to be proficient in a computer programming language.

There is a plethora of programming languages available these days that satisfy many needs. Currently, one of the more popular and also faster growing languages is Python. It is a free and open-source general purpose programming language that focuses on readability and expandability. In recent years, Python has proven to be a very capable language for scientific applications, which has led to the creation of numerous useful code libraries. These “scientific Python” packages provide the ability to perform mathematical operations and numerical analysis of arrays using the NumPy and Panda libraries, data visualization with the Matplotlib library, instrument communication with the PyVISA library, experiment design and data acquisition with the PyMeasure library, image analysis with the scikit-image library, and machine learning-based analysis of complex problems with the PyTorch library. With current estimates placing the number of readily available Python libraries near 100,000, which includes many scientific-focused libraries, the Python programming language is a powerful tool when solving engineering-based problems.

This guide is designed to be a starting point for anyone who wants to learn Python with a focus on science and engineering applications. We have written this guide assuming that the reader has no background experience in coding but has a high school education level in mathematical concepts. This guide has been designed such that a reader will not be an “expert” after completing these lessons, but rather should be proficient in reading Python code, understand how to make their own small Python programs, be comfortable in reading error messages, and know how to search for new functionality. There are 12 detailed lessons that go over many basic aspects of coding in Python for scientific applications. Each lesson contains usable code blocks that the reader can actively follow and execute on their own computer. In addition to these blocks of code, there are more than 30 additional short example problems (with solutions) that further instruct many of the basic tenants in Python programming for scientific applications.

We hope this guide can be used as a centralized, standard starting point for Python education. Lessons build off one another, so it is recommended that a user start with the first lesson. Regardless if this is your first programming language, or you have programmed before, we hope you enjoy these lessons on your path to learning the basics of Python for scientific applications. When you are ready, start the first lesson that covers how to get Python running on your computer, so you can begin your journey to learn about this powerful programming language!