Python is a popular programming language used in scientific research, engineering, social sciences, and finance. It is an object-oriented language that can be used in many different ways. For example, it can be used for scripting, web development, data analysis and visualization, machine learning, game development, computer graphics and natural language processing.
It also happens to be a flexible and powerful programming language that allows you to explore mathematical concepts in depth. You can use Python for solving complex equations or to simulate the movement of stars around the sun or some other computation. For this reason, many mathematicians find Python to be an excellent tool.
Python is easy to learn, has a large community, and offers many libraries that can make complex mathematical tasks much easier to accomplish.
Here are some libraries that you might find useful if you deal with mathematics on a regular basis.
1. The Math Module
This is a python module that allows programmers to beyond simple additions and subtractions by providing numerous mathematical functions for basic operations such as exponentials, modulus, factorials and even trigonometric functions.
This library is not suitable for complex mathematical operations such as multiplication of matrices but very sufficient for basic mathematical operations.
NumPy is a Python library that supports large, multi-dimensional arrays and matrices making it the most fundamental and useful mathematics and computing library available today. It comes along with a huge collection of high-level mathematical functions that manipulate numerical data and also operate on the various n-dimensional arrays and matrices it supports.
NumPy is often used in fields such as data analysis, numerical computation, machine learning, and visualization.
You can install numpy by running this command in your terminal:
pip install numpy
Check out the numpy documentation for more on how to use it.
SymPy is a lightweight Python library for numeric and symbolic mathematics. It is used in simplifying algebraic expressions, manipulating matrices, solving equations, and plotting data. It also provides an interface for using Maxima on the command line. Sympy aims to be a full-featured computer algebra system (CAS) and is also designed to integrate well with other packages such as NumPy and SciPy which provide fast arrays and matrices. Here are a few fields where sympy is found to be incredibly useful: polynomials, calculus, matrices, geometry, physics, plotting, combinatorics, statistics, cryptography, etc.
You can install sympy by running this command in your terminal:
pip install sympy
Theano was a Python library that allows you to define, optimize, and evaluate mathematical expressions involving multi-dimensional arrays. Theano features an easy-to-use interface for defining functions, allowing them to be efficiently compiled and optimized, and also offers many common mathematical functions to build more complicated calculations.
Much of the power of Theano comes from its ability to compute on arrays in both CPU and GPU modes. It has support for nearly all data types found in Numpy, including support for converting other datatypes into Numpy arrays. Though further improvements to this library have been halted, it remains a popular and efficient choice for a lot of developers who work with multi-dimensional arrays.
Run this command to install Theano:
pip install theano
It's an open-source python module that provides a comprehensive set of tools for statistical analysis of data sets. Statsmodels provides classes and tools for the estimation of statistical models, such as linear regression, generalized linear models, nonlinear least squares and maximum likelihood. Statsmodel has features that will appeal to both beginners and experienced users alike and prove to be best when it comes to statistical computing. Check out the documentation for more.
Run this command to install
pip install statsmodel
Pandas is a Python library that provides fast, flexible, and expressive data structures designed to make working with relational and numeric tables both easy and intuitive. It is one of the most popular libraries for data manipulation and data analysis in Python.
The goal of the pandas project is to provide a high-performance, easy-to-use toolset for working with structured (tabular, multidimensional, potentially heterogeneous) and time-series data sets. Thus, it forms a useful package in the toolkit of a mathematician or statistician.
Scipy is a library for scientific computing. At its core, it is made up of various numeric and scientific computing packages providing the tools needed for solving problems in mathematics, science, engineering and even economics. You can use it to optimize performance or compute more efficiently. The goal of scipy is to provide a powerful and flexible package at an accessible level without sacrificing efficiency.
It provides routines for manipulating arrays, matrices, and other kinds of multidimensional data; performing linear algebra operations; working with probability distributions, statistics, and random number generators; generating graphical displays; and carrying out many other mathematical operations.
Matplotlib is an open-source plotting library for Python and NumPy, its extension to numerical mathematics. It allows you to create interactive, static and animated visualizations and has been extensively used by scientists, mathematicians and programmers because of its ease of use and many features.
With just a few lines of code, matplotlib can produce quality 2D plots and figures that can be exported and embedded in interactive environments. It gives users various options of customization and tailored functionality when visualizing data.
9. Scikit Learn
Scikit-learn is a python library for machine learning(predictive data analysis), which is the field of study concerned with giving computers the ability to learn without being explicitly programmed. It provides a solid foundation for machine learning and data mining, and it can be used both in research and production environments.
Scikit-learn is built on NumPy, SciPy, and matplotlib and thus provides out of the box fundamental mathematical tools needed for machine learning such as linear algebra, analytic geometry, matrix decompositions, vector calculus, optimization, probability and statistics.
Dask is a Python package that provides flexible, efficient and easy-to-use parallel computing. If you want to perform some kind of computational task on a subset of data across multiple computers or CPUs, Dask will provide the tools to do so. It works with different types of distributed systems, allows the user to express parallelism as a task dependency graph, and provides tools to load data into a cluster or process it without a cluster.
It is developed in coordination with other python projects like NumPy, pandas, and scikit-learn.
Patsy is a python package for developing statistical models(usually linear models) and building design matrices. This project is intended to be the standard interface for describing Python statistical models.
These libraries are mostly domain-specific but usually, for doing regular math in python, the math module and Numpy are the best. You should consider the other libraries when doing advanced tasks like parallel computation or linear regression. Check out this course on using python for mathematics.