This set of Python programs is about creating a collage and then adding a contour to it. import numpy as np import matplotlib.pyplot as plt import matplotlib.image as im import random random.seed(123) l = [] a = list(range(1, 37)) random.shuffle(a) for i in a: if i == 35: continue image = im.imread(‘images/collagephoto{}.jpg’.format(i)) l.append(image) l1 = […]
Category: Python
Natural Language Processing with Dante
In this period, I’m studying natural language processing and its applications. One of my favourite tricks is generating text which reminds someone’s style. For example, here I will show an AI (trained for 100 minutes and just two epochs) that has learned to fake Dante’s Divine Comedy. import tensorflow as tffrom tensorflow import kerasimport numpy […]
An Old Birthday Gift
This is an old birthday gift for a special person. It was the first time I tried to plot something using python, and I wasn’t very familiar with matplotlib, so I used the turtle library. import turtleimport timedef auguri(): colors = [‘blue’, ‘red’, ‘green’, ‘yellow’, ‘orange’, ‘purple’] turtle.pensize(5) turtle.bgcolor(‘black’) turtle.speed(1000) for x in range(360): turtle.pencolor(colors[x […]
Plotting 3D Lines
In Python as you know there’s the option of plotting 3D graphs, so why not fully exploiting such possibilities? In this example I will show a sort of an irregular spiral figure. import matplotlib as mplimport numpy as npimport matplotlib.pyplot as pltmpl.rcParams[‘legend.fontsize’] = 10fig = plt.figure()ax = fig.gca(projection=’3d’)theta = np.linspace(-4 * np.pi, 4 * np.pi, […]
Multiple Days Stock Predictor
The last stock predictor could only predict the following day based on the last n days. Now it can predict any number of days ahead. Since when you try to predict more days ahead some may overlap, this plot is made by taking the mean of all the overlapping days. Hence, it’s not very accurate, […]
Very Elegant Image Color Segmentation
Let’s start with this suggestive image of a tree with pink flowers on it. What I want to do is simplifying it to see its main colors. How can I do it? Well, here some unsupervised learning techniques may come in handy. Clustering the pixels of the image, which are no other than points in […]
Recursive Solution To A Nice Problem
There is a frog jumping on lily pads labeled with natural numbers. It’s on the 2015th lily pad and can either go one step forward or backwards, except if it at any time is on a lily pad divisible by 6 it has to go forward. How many 15-steps paths are possible? The problem is […]
Plotting Epicycloids
An epicycloid is the figure that a fixed point of a circle draws when the circle rotates on the circumference of another one. How to plot such things in Python? There is a trick: such figures depend on the ratio of the still circle’s and the rotating circle’s radius. Let’s say we have an integer […]
Python Basic Stock Predictor
Machine learning in economy is very important, and one of its application is predicting the behavior of the stock market. How can you do that, the idea is creating a model that reads the previous graph of the market and gives the predicted behavior as output. To do so, one cannot use the simple Tensorflow […]
AI Artist
A nice programming challenge is writing a program that modifies an image to give using the style from another image, which in my case is Van Gogh’s Starry Night. Let’s take a look at the input image. A take of the houses of parliament at night. Now let’s see the output image after 7000 iterations. […]