Python math module and data science

How does the python math module relate to data science? As a beginner you may wonder.

We’ll come to that point in a minute. 

But before that, we would like to discuss the math module in Python.

Firstly, python from the very beginning has the in-built mathematics library.

As a result, we don’t have to explicitly install it. 

We can import the math module as follows.

import math as m

In today’s discussion we will take a look at the math constants which are extremely necessary in python programming and data science.

import math as m

circumference_by_diameter = m.pi
print(circumference_by_diameter)

# 3.141592653589793

We’ve heard about the famous constant “pi” which is a constant floating point number.

And in python it equals 3.141592653589793.

After the point, python gives 15 digits. However, as an irrational number it might be bigger than that.

We also know that “pi” is the ratio of circumference of a circle to the diameter of that circle.

Therefore, if we have a value of diameter like 3, we can easily calculate the value of the circumference.

diameter = 3
# if d = 3, c = pi * d
circumference = m.pi * diameter
print(circumference)
# 9.42477796076938

Like “pi”, another constant value that we get from the math module is “tau”.

What is “tau”?

Just like “pi”, the constant “tau” is the ratio of circumference of a circle to the radius of that circle.

circumference_by_radius = m.tau
print(circumference_by_radius)
6.283185307179586
# tau = c / r
# r = d / 2, c = tau * r
circumference = m.tau * (diameter / 2)
print(circumference)
# 9.42477796076938

However, one of the math module constants is Euler’s number. 

Euler’s number, math module and data science

In fact, without Euler’s number we cannot think of machine learning algorithms. As an outcome, we cannot think of data science without machine learning algorithms.

To summarize, with the help of Euler’s number we can explain everything from exponential growth to decay.

In financial data analysis we can predict how wealth can grow due to compound interest. 

We can get the Euler’s number as follows.

eulers_number = m.e
print(eulers_number)
# 2.718281828459045

By the way, when we discuss the natural logarithm, we will explain Euler’s number in great detail.

Why?

Because it’s the base of the natural logarithm.

We’ll also discuss why understanding natural logarithm is important in Data science.

What Next?

Books at Leanpub

Books in Apress

My books at Amazon

GitHub repository

Flutter, Dart and Algorithm

Twitter

Comments

One response to “Python math module and data science”

  1. […] However, we can do the same thing with NumPy and Matplotlib. […]

Leave a Reply