0

My Python program:

#!/usr/bin/python
from pylab            import plot,show
from numpy            import vstack,array
from numpy.random     import rand
from scipy.cluster.vq import kmeans, vq, whiten

import csv

if __name__ == "__main__":

    K = 3

    data_arr = []

    clust_name_arr = []

    with open('clustering.csv', 'rb') as f:

        reader = csv.reader(f)

        for row in reader:

            data_arr.append([float(x) for x in row[1:]])

            clust_name_arr.append([row[0]])

    data = vstack( data_arr )

    clust_name = vstack(clust_name_arr)

   data = whiten(data)



    centroids, distortion = kmeans(data,3)

    print "distortion = " + str(distortion)



    idx,_ = vq(data,centroids)



    plot(data[idx==0,0], data[idx==0,1],'ob',

         data[idx==1,0], data[idx==1,1],'or',

         data[idx==2,0], data[idx==2,1],'og')

    print clust_name

    print data

    for i in range(K):

        result_names = clust_name[idx==i, 0]

        print "================================="

        print "Cluster " + str(i+1)

        for name in result_names:

            print name

    plot(centroids[:,0],

         centroids[:,1],

         'sg',markersize=8)

    show()

Error Message: Traceback (most recent call last): File "/Users//Desktop/Assignment4(2).py", line 7, in from pylab import plot,show File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pylab.py", line 1, in from matplotlib.pylab import * File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/pylab.py", line 222, in from matplotlib import mpl # pulls in most modules File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/mpl.py", line 1, in from matplotlib import artist File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/artist.py", line 7, in from transforms import Bbox, IdentityTransform, TransformedBbox, \ File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/transforms.py", line 35, in from matplotlib._path import (affine_transform, count_bboxes_overlapping_bbox, ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_path.so, 2): no suitable image found. Did find: /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/_path.so: no matching architecture in universal wrapper

5
  • Did you have a question? What did you try? How did you install Python? What are the error messages? Come on - please try harder if you want help. Nov 17, 2017 at 10:04
  • I already installed python version 3.7 but I want to know how I import python libraries in my program. pylab, numpy etc.Error message:
    – rubaya
    Nov 17, 2017 at 16:51
  • Please click edit under your original question and make sure you include answers for all the questions in my first comment. Nov 17, 2017 at 16:54
  • I include the error message
    – rubaya
    Nov 17, 2017 at 17:30
  • And my other 2 questions? Nov 17, 2017 at 18:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.