On machine learning sites, we often see plots of points in an ellipse. I didn't know how to make it, so I tried to make it by playing with Numpy.
ellipseLike.py
import numpy as np
import matplotlib.pyplot as plt
#Number of outputs
n = 1000
#Generate random numbers
x = np.random.uniform(-4, 4, n)
y = np.random.uniform(-1, 1, n)
#filtering
coordinates = np.array([((x[i])**2 + (y[i])**2)**(1/2) < 1 for i in range(n)])
index = np.where(coordinates==True)
#Manipulate coordinates
x_points = x[index] *4
y_points = y[index]
#Rotate and move coordinates(30 degrees)
x_points2 = x_points * (3**(1/2)) - y_points * (1/2)
y_points2 = x_points * (1/2) + y_points * (3**(1/2))
#plot
plt.scatter(x_points2, y_points2)
plt.show()
I learned about the multivariate normal distribution after I finished making it. I didn't study enough ...
Thank you for visiting. If you have any comments or suggestions, please do not hesitate to contact us.
Recommended Posts