Python program to find distance measure - Hamming ,Euclidean , Manhattan, Minkowski

# Calculating distance between bit strings

# Hamming Distance
def hamming_distance(a, b):
return sum(abs(e1 - e2) for e1, e2 in zip(a, b)) / len(a)
r1 = [1, 0, 0, 0, 0, 0, 1]
r2 = [1, 0, 0, 0, 0, 1, 0]
dist = hamming_distance(r1, r2)

#Euclidean Distance
from math import sqrt
def euclidean_distance(a, b):
return sqrt(sum((e1-e2)**2 for e1, e2 in zip(a,b)))
r1 = [1, 0, 0, 0, 0, 0, 1]
r2 = [1, 0, 0, 0, 0, 1, 0]
dist = euclidean_distance(r1, r2)

#Manhattan Distance
from math import sqrt
def manhattan_distance(a, b):
return sum(abs(e1-e2) for e1, e2 in zip(a,b))
r1 = [1, 0, 0, 0, 0, 0, 1]
r2 = [1, 0, 0, 0, 0, 1, 0]
dist = manhattan_distance(r1, r2)

#Minkowski Distance
from math import sqrt
def minkowski_distance(a, b, p):
return sum(abs(e1-e2)**p for e1, e2 in zip(a,b))**(1/p)
r1 = [1, 0, 0, 0, 0, 0, 1]
r2 = [1, 0, 0, 0, 0, 1, 0]
dist = minkowski_distance(r1, r2, 1) #  p=1: Manhattan distance.
dist = minkowski_distance(r1, r2, 2) #  p=2: Euclidean distance.

Counter using Tkinter GUI in Python

 import tkinter as tk

counter = 0
def counter_label(label):
def count():
global counter
counter += 1
label.after(1000, count)

root = tk.Tk()
root.title("Counting Seconds")
label = tk.Label(root, fg="green")
button = tk.Button(root, text='Stop', width=25, command=root.destroy)

Generate random numbers with normal distribution

 1.Generate normal distribution data of Size 2 × 3

   from numpy import random
   x = random.normal(size=(23))

2. Generate normal distribution with mean 250 and standard deviation 10

    from numpy import random
    x = random.normal(loc=250, scale=10, size=(23))

Python Random Module

 import random


random.uniform(1, 10)

random.randint(1, 10)

random.randrange(0, 101, 2)


items = [1, 2, 3, 4, 5, 6, 7]



random.sample([1, 2, 3, 4, 5],  3)

Python may get pattern matching syntax

PEP 622 -- Structural Pattern Matching is PEP proposes adding pattern matching statements  to Python in order to create more expressive ways of handling structured heterogeneous data. The authors take a holistic approach, providing both static and runtime specifications.

PsychoPy - Precise enough for psychophysics is a package for the generation of experiments for neuroscience and experimental psychology.It is designed to allow the presentation of stimuli and collection of data for a wide range of neuroscience, psychology, and psychophysical experiments

Python program to find number of processors in your computer

The maximum parallel processes can you run on computer is based on the number of processors or cores  in your computer. To find number of processors or cores  in your computer, cpu_count() function is used.

import multiprocessing as mp
print("Number of processors: ", mp.cpu_count())


A tiny Python package for easy access to up-to-date Coronavirus (COVID-19, SARS-CoV-2) cases data.

Installation - pip install COVID19Py

Usage -  To use COVID19Py, you first need to import the package and then create a new instance:

import COVID19Py
covid = COVID19Py.COVID()

Python Programming for Quantitative Economics

This website presents a set of lectures on python programming for quantitative economics, designed and written by Thomas J. Sargent and John Stachurski.


A python program for neural network trained with backpropagation with sigmoid function

import numpy as np
def nonlin(x,deriv=False):
return x*(1-x)
return 1/(1+np.exp(-x))
X = np.array([ [0,0,1],
[1,1,1] ])
y = np.array([[0,0,1,1]]).T
syn0 = 2*np.random.random((3,1)) - 1
for iter in range(10000):
l0 = X
l1 = nonlin(,syn0))
l1_error = y - l1
l1_delta = l1_error * nonlin(l1,True)
syn0 +=,l1_delta)
print ("Output After Training:")
print (l1)

Google reveals new Python programming language course

Google creates a new Python training certificate to boost your chances of getting a job.The new training course, called the Google IT Automation with Python Professional Certificate, is being run by online education firm Coursera. 

There are 6 Courses in this Professional Certificate

Course - 1  Crash Course on Python
Course - 2  Using Python to Interact with the Operating System
Course - 3  Introduction to Git and GitHub
Course  - 4  Troubleshooting and Debugging Techniques
Course  - 5  Configuration Management and the Cloud
Course  - 6  Automating Real-World Tasks with Python

First Come First Serve Process scheduling using python

process = []
total_waiting_time = 0
n = int(raw_input('Enter the total no of processes: '))
for i in xrange(n):
    process[i].append(raw_input('Enter process name: '))
    process[i].append(int(raw_input('Enter process arrival time : ')))
    total_waiting_time += process[i][1]
    process[i].append(int(raw_input('Enter process  burst time: ')))
    print ''

process.sort(key = lambda process:process[1])

print 'Process Name\tArrival Time\tBurst Time'
for i in xrange(n):
    print process[i][0],'\t\t',process[i][1],'\t\t',process[i][2]
print 'Total waiting time: ',  total_waiting_time
print 'Average waiting time: ',(total_waiting_time/n)

Python Any Where - Host, run, and code Python in the cloud

Basic plan gives you access to machines with a full Python environment already installed for free. You can develop and host your website or any other code directly from your browser without having to install software or manage your own server.

Python Any Where


Metaflow is a human-friendly Python library that helps scientists and engineers build and manage real-life data science projects. Metaflow was originally developed at Netflix to boost productivity of data scientists who work on a wide variety of projects from classical statistics to state-of-the-art deep learning.

pip install metaflow