Scientific and numerical computing is a booming field in research, engineering, and analytics. The revolution in the computer industry over the last several decades has provided new and powerful tools for computational practitioners. This has enabled computational undertakings of previously unprecedented scale and complexity. Entire fields and industries have sprung up as a result. This development is still ongoing, and it is creating new opportunities as hardware, software, and algorithms keep improving. Ultimately the enabling technology for this movement is the powerful computing hardware that has been developed in recent decades. However, for a computational practitioner, the software environment used for computational work is as important as, if not more important than, the hardware on which the computations are carried out. This book is about one popular and fast-growing environment for numerical computing: the Python programming language and its vibrant ecosystem of libraries and extensions for computational work.
Computing is an interdisciplinary activity that requires experience and expertise in both theoretical and practical subjects: a firm understanding of mathematics and scientific thinking is a fundamental requirement for effective computational work. Equally important is solid training in computer programming and computer science. The role of this book is to bridge these two subjects by introducing how scientific computing can be done using the Python programming language and the computing environment that has appeared around this language. In this book the reader is assumed to have some previous training in mathematics and numerical methods and basic knowledge about Python programming. The focus of the book is to give a practical introduction to computational problem-solving with Python. Brief introductions to the theory of the covered topics are given in each chapter, to introduce notation and remind readers of the basic methods and algorithms. However, this book is not a self-consistent treatment of numerical methods. To assist readers that are not previously familiar with some of the topics of this book, references for further reading are given at the end of each chapter. Likewise, readers without experience in Python programming will probably find it useful to read this book together with a book that focuses on the Python programming language itself.
How This Book Is Organized
The first chapter in this book introduces general principles for scientific computing and the main development environments that are available for work with computing in Python: the focus is on IPython and its interactive Python prompt, the excellent Jupyter Notebook application, and the Spyder IDE.
In Chapter 2, an introduction to the NumPy library is given, and here we also discuss more generally array-based computing and its virtues. In Chapter 3, we turn our attention to symbolic computing – which in many respects complements array-based computing – using the SymPy library. In Chapter 4, we cover plotting and visualization using the Matplotlib library. Together, Chapters 2 to 4 provide the basic computational tools that will be used for domain-specific problems throughout the rest of the book: numerics, symbolics, and visualization.
In Chapter 5, the topic of study is equation solving, which we explore with both numerical and symbolic methods, using the SciPy and SymPy libraries. In Chapter 6, we explore optimization, which is a natural extension of equation solving. Here we mainly work with the SciPy library and briefly with the cvxopt library. Chapter 7 deals with interpolation, which is another basic mathematical method with many applications of its own, and important roles in higher-level algorithms and methods. In Chapter 8, we cover numerical and symbolic integration. Chapters 5 to 8 cover core computational techniques that are pervasive in all types of computational work. Most of the methods from these chapters are found in the SciPy library.
In Chapter 9, we proceed to cover ordinary differential equations. Chapter 10 is a detour into sparse matrices and graph methods, which helps prepare the field for the following chapter. In Chapter 11, we discuss partial differential equations, which conceptually are closely related to ordinary differential equations, but require a different set of techniques that necessitates the introduction of sparse matrices, the topic of Chapter 10.
Starting with Chapter 12, we make a change of direction and begin exploring data analysis and statistics. In Chapter 12, we introduce the Pandas library and its excellent data analysis framework. In Chapter 13, we cover basic statistical analysis and methods from the SciPy stats package. In Chapter 14, we move on to statistical modeling,using the stats models library. In Chapter 15, the theme of statistics and data analysis is continued with a discussion of machine learning, using the scikit-learn library. In Chapter 16, we wrap up the statistics-related chapters with a discussion of Bayesian statistics and the PyMC library. Together, Chapters 12 to 16 provide an introduction to the broad field of statistics and data analytics: a field that has been developing rapidly within and outside of the scientific Python community in recent years.
In Chapter 17, we briefly return to a core subject in scientific computing: signal processing. In Chapter 18, we discuss data input and output, and several methods for reading and writing numerical data to files, which is a basic topic that is required for most types of computational work. In Chapter 19, the final regular chapter in this book,two methods for speeding up Python code are introduced, using the Numba and Cython libraries.
The Appendix covers the installation of the software used in this book. To install the required software (mostly Python libraries), we use the conda package manager. Conda can also be used to create virtual and isolated Python environments, which is an important topic for creating stable and reproducible computational environments. The Appendix also discusses how to work with such environments using the conda package manager.
Source Code Listings
Each chapter in this book has an accompanying Jupyter Notebook that contains the chapter’s source code listings. These notebooks, and the data files required to run them,can be downloaded by clicking the Download Source Code button located at www.apress.com/9781484242452.