Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- import matplotlib.pyplot as plt
- import random
- N=25
- r=np.random.normal(0,2,2*N);
- the=2*np.pi*np.random.rand(2*N);
- x=np.ones([2*N,2]);
- x[0:N,0]=5 + r[0:N]*np.cos(the[0:N])
- x[0:N,1]=10 + r[0:N]*np.sin(the[0:N])
- x[N:2*N,0]=10 + r[N:2*N]*np.cos(the[N:2*N])
- x[N:2*N,1]=5 + r[N:2*N]*np.sin(the[N:2*N])
- n = random.sample(list(range(0,50)), 20)
- red = x[n]
- blue = np.delete(x, n, 0)
- plt.figure(figsize=(10,10))
- plt.scatter(blue[:,0], blue[:,1],marker='s')
- plt.scatter(red[:,0], red[:,1], marker='o',c = 'r')
- closer_p= 0
- closer_q = 0
- p = np.array([(5,10)], dtype = np.int64)
- q = np.array([(10,5)], dtype = np.int64)
- for point in red:
- d1 = np.linalg.norm(p-point)
- d2 = np.linalg.norm(q-point)
- if d1 < d2:
- closer_p+=1
- else:
- closer_q+=1
- print(closer_p)
- print(closer_q)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement