<commit_before>from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.cluster import KMeans


im = Image.open("test.jpg")
pix = im.load()
x_max = im.size[0]
y_max = im.size[1]
R = np.zeros((x_max*y_max,3),dtype=np.int)
G = np.zeros((x_max*y_max,3),dtype=np.int)
B = np.zeros((x_max*y_max,3),dtype=np.int)
# print "x_max = {0} y_max = {1}".format(x_max,y_max)
# G = np.zeros(im.size)
# B = np.zeros(im.size)

k =0
for i in range(1,x_max):
	for j in range(1,y_max):
		R[k,:] = np.array([i,j,pix[i,j][0]]) 
		G[k,:] = np.array([i,j,pix[i,j][1]]) 
		B[k,:] = np.array([i,j,pix[i,j][2]]) 
		k+=1
		# G[i,j] = pix[i,j][1]
		# B[i,j] = pix[i,j][2]
		# # A[i,j] = pix[i,j][3]
for x in (R,G,B):
	print "********************"
	k_means = KMeans(init='k-means++', n_clusters=9, n_init=10)
	k_means.fit(x)
	print k_means.cluster_centers_

# fignum = 1
# for name, est in estimators.items():
#     fig = plt.figure(fignum, figsize=(4, 3))
#     plt.clf()
#     ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=48, azim=134)

#     plt.cla()
#     est.fit(R)
#     labels = est.labels_<commit_msg>Used double map fuction to speed stuff up<commit_after>from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.cluster import KMeans

# define some parameters
im = Image.open("test.jpg")
pix = im.load()
x_max = im.size[0]
y_max = im.size[1]
rgb_vals = np.zeros((x_max*y_max,5),dtype=np.int)
x_vals = np.arange(0,x_max)
y_vals = np.arange(0,y_max)

def create_vals(i,j):
	return  np.array([pix[i,j][0],pix[i,j][1],pix[i,j][2]])
# G = np.zeros((x_max*y_max,3),dtype=np.int)
# B = np.zeros((x_max*y_max,3),dtype=np.int)
# print "x_max = {0} y_max = {1}".format(x_max,y_max)


rgb_vals = np.array(map(lambda i : map(lambda j : create_vals(i,j),y_vals),x_vals))
# for i in range(1,x_max):
# 	for j in range(1,y_max):
# 		Z[k,:] = np.array([i,j,pix[i,j][0],pix[i,j][1],pix[i,j][2]])
# 		k+=1
# 		# G[i,j] = pix[i,j][1]
# 		# B[i,j] = pix[i,j][2]
print "{0} {1} {2}".format(rgb_vals.shape,x_max,y_max)
# fig = plt.figure()
# ax = fig.add_subplot(111, projection='3d')	
# k_means = KMeans(init='k-means++', n_clusters=9, n_init=100)

# k_means.fit(Z)
# z.append(k_means.cluster_centers_)


# for x in k_means.cluster_centers_:
# 	plt.scatter(x[0],x[1])

# plt.show()

# ax.scatter(np.arange(1,10),np.arange(1,10),np.arange(1,10))


# fignum = 1
# for name, est in estimators.items():
#     fig = plt.figure(fignum, figsize=(4, 3))
#     plt.clf()
#     ax = Axes3D(fig, rect=[0, 0, .95, 1], elev=48, azim=134)

#     plt.cla()
#     est.fit(R)
#     labels = est.labels_
{'fraction_non_alphanumeric': 0.22135125046659201, 'fraction_numerical': 0.03508771929824561, 'mean_word_length': 4.469387755102041, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7099092', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1313, 'n_words': 225}