For a lot of us, finding the greatest common denominator between numbers was a common exercise in grade school math. However, in the real world finding GCDs can form an integral part of our algorithms and analysis. In this article we shall go over how to get GCDs under different scenarios.
Let’s begin!
“Create a function that will take two integers as inputs and find their Greatest Common Denominator.”
Sounds simple enough, let’s see a typical algorithm that find the GCD of two integers. A common algorithm is the one below:
def get_gcd_1(num1, num2): while num1 != num2: if num1…
Duplicate detecting and indexing is a fundamental skill every data scientist should have. When dealing with any dataset, it is important to identify and locate values that are identical. In this article, we shall take a look at several techniques you can use.
Let’s get started!
So let’s say you were given the below question.
“Create a function that would check if a list has duplicate values, if it does have duplicate values list them all. If the list has no duplicates return “No Duplicates”.
Fairly simple question, let us see how to code it.
def duplicates(example_list): return len(example_list) !=…
One of the challenges of being a data scientist is solving unique problems that leave most people scratching their heads. These range from seemingly innocuous textbook exercises to complex riddles left unsolved for years. In this article we shall go over some light to intermediate problems that will help you better understand how to decipher encrypted messages. We shall then apply our learnings to solve a basic deciphering exercise.
Let’s say the question was:
“Get the sum of all the digits in an integer, make the solution generalizable enough to work with any integer”
Assuming that the number given to…
List comprehension is a powerful tool that allows Python programmers to write codes in an extremely condensed fashion. In this article we will go over how to use list comprehension to simplify otherwise complex functions.
Let’s begin!
To start off, let’s create a sample string.
sample_string = 'sample_for_list_comprehension'
Now let us create a Python list that contains every character of that string as its elements.
sample_list =[]
for s in sample_string:
sample_list.append(s)
sample_list
One of the most interesting aspects of the Python language are Lambda functions. For programmers who are skilled at reducing their codes into simple logical statements, Lambda functions help shrink the number of lines dramatically. In this article we shall go over what Lambda functions are and how to apply them in practical ways in Python.
Let’s begin!
Say you have a function that multiplies any number you put into it by 10.
def mult_ten(original):
return original * 10number = mult_ten(5)
Python is an excellent language for new programmers to learn. Its intuitive nature makes it easy for most people to quickly understand what the codes and algorithms are actually doing. In this article and many others in the future, we will be going over the many ways one can use Python to solve beginner exercises to more complicated problems. Note that for all these articles I will be making use of a Jupyter Notebook to show the results of the code.
Let’s begin!
So lets imagine you were given a list of words and had to extract specific metrics from…
One of the most important skills a data scientist can learn is how to craft a convincing story using the given data. Though we tend to think of our work as being objective and technical, encapsulated in the adage “Numbers don’t lie”, we should also be aware of its more subjective aspects. We should not fall into the trap of viewing our work as completely detached from our own impressions and preconceived notions of the world.
In this article I will go over the many ways the same data set can be used to craft different (and sometimes conflicting) narratives…
In a previous article, we explored the idea of applying the K-Means algorithm to automatically segment our image. However, we only focused in on the RGB Color Space. Of course the RGB color space is the native format for most images, however in this article we shall go beyond it and see the effects of using different color spaces on the resulting clusters.
Let’s get started!
As per usual, let us begin by importing the required Python libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3D from matplotlib import colors from skimage.color…
So far most of the techniques we’ve gone over have required us to manually segment the image via its features. But we can actually use unsupervised clustering algorithms to do this for us. In this article we shall go over how to do just that.
Let’s begin!
As always, we start by importing the required Python libraries.
import numpy as np
import pandas as pd
import matplotlib.pyplot as pltfrom mpl_toolkits.mplot3d import Axes3D
from matplotlib import colors
from skimage.color import rgb2gray, rgb2hsv, hsv2rgb
from skimage.io import imread, imshow
from sklearn.cluster import KMeans
Excellent, let us now import the image we…
Segmenting images by their color is an extremely useful skill to have. I’ve previously written an article on how to do this via the RGB and HSV color spaces. However, another effective way to segment images based on their color is by making use of RG Chromaticity and the Gaussian Distribution. This article will discuss how to do just that.
Let’s begin!
As always, first import the required Python libraries.
import numpy as np
import matplotlib.pyplot as plt
from skimage.io import imread, imshow
from numpy import ndarray
from matplotlib.patches import Rectanglefrom mpl_toolkits.mplot3d import Axes3D from matplotlib import cm from…
Just a kid that writes about data and the world.