Skip to content

Instantly share code, notes, and snippets.

@ronekko
Created January 6, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ronekko/61cb4931c4a58adf68c68452c4434f5f to your computer and use it in GitHub Desktop.
Save ronekko/61cb4931c4a58adf68c68452c4434f5f to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
"""
Created on Sat Jan 6 23:41:17 2018
@author: sakurai
"""
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import pairwise_distances
if __name__ == '__main__':
n = 3
dim_y = 2
center_0 = np.array([3, 4], dtype='f')
Y_0 = center_0 + np.random.randn(n, dim_y)
center_1 = np.array([-2, -1], dtype='f')
Y_1 = center_1 + np.random.randn(n, dim_y)
print('Y_0:')
print(Y_0)
print('Y_1:')
print(Y_1)
plt.plot(Y_0.T[0], Y_0.T[1], '.', label='c=0')
plt.plot(Y_1.T[0], Y_1.T[1], '.', label='c=1')
plt.legend()
plt.gca().set_aspect('equal')
plt.grid()
plt.show()
Y = np.vstack((Y_0, Y_1))
print('Y:')
print(Y)
print()
D = pairwise_distances(Y)
print('Distance matrix of Y')
print(D) # See `D` in "Variable explorer"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment