Skip to content

Instantly share code, notes, and snippets.

@azizkayumov
Created June 2, 2020 09:57
Show Gist options
  • Save azizkayumov/49771facadcccc3507058f30f0ea9098 to your computer and use it in GitHub Desktop.
Save azizkayumov/49771facadcccc3507058f30f0ea9098 to your computer and use it in GitHub Desktop.
import numpy as np
import matplotlib.pyplot as plt
import time
# Class 1:
mean_1 = [-2, 1]
cov1 = [[1, 0.8], [0.8, 2]]
# Class 2:
mean_2 = [3, -2]
cov2 = [[3, 0.8], [0.8, 2]]
# create subplot
fig = plt.figure()
ax = fig.add_subplot(111)
# generate 100 data points for Class 1
xy = np.random.multivariate_normal(mean_1, cov1, 100)
x1, y1 = xy[:,0], xy[:,1]
ax.scatter(x1, y1, color='r')
# generate 100 data points for Class 2
xy = np.random.multivariate_normal(mean_2, cov2, 100)
x2, y2 = xy[:,0], xy[:,1]
ax.scatter(x2, y2, color='b')
# write to file
file = open("data.txt", "w")
for i in range(len(x1)):
line = str(x1[i]) + "," + str(y1[i]) + "," + "0\n"
file.write(line)
for i in range(len(x2)):
line = str(x2[i]) + "," + str(y2[i]) + "," + "1"
if i != len(x2) - 1:
line += "\n"
file.write(line)
file.close()
ax.set_title('Assignment #2. Task 2.a')
plt.grid()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment