title: Python - Issue with the dimension of array in cdist function
body: <p>I am trying to find the right number of cluster for k-means and using the <strong>cdist</strong> function for this.</p>
  
  <p>I can understand the argument for <strong>cdist</strong> should be of same dimension. I tried printing the size of both argument which is (2542, 39) and (1, 39).</p>
  
  <p>Can someone please suggest where i am going wrong ?</p>
  
  <pre><code>print(tfidf_matrix.shape) ### Returning --&gt; (2542, 39)
  #Finding optimal no. of clusters
  from scipy.spatial.distance import cdist
  clusters=range(1,10)
  meanDistortions=[]
  
  for k in clusters:
      model=KMeans(n_clusters=k)
      model.fit(tfidf_matrix)
      prediction=model.predict(tfidf_matrix)
      print(model.cluster_centers_.shape)  ## Returning (1, 39)
      meanDistortions.append(sum(np.min(cdist(tfidf_matrix, model.cluster_centers_, 'euclidean'), axis=1)) /
                             tfidf_matrix.shape[0])
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-181-c15e32d863d2&gt; in &lt;module&gt;()
       12     prediction=model.predict(tfidf_matrix)
       13     print(model.cluster_centers_.shape)
  ---&gt; 14     meanDistortions.append(sum(np.min(cdist(tfidf_matrix, model.cluster_centers_, 'euclidean'), axis=1)) /
       15                            tfidf_matrix.shape[0])
       16 
  
  ~\Downloads\Conda\envs\data-science\lib\site-packages\scipy\spatial\distance.py in cdist(XA, XB, metric, *args, **kwargs)
     2588 
     2589     if len(s) != 2:
  -&gt; 2590         raise ValueError('XA must be a 2-dimensional array.')
     2591     if len(sB) != 2:
     2592         raise ValueError('XB must be a 2-dimensional array.')
  
  ValueError: XA must be a 2-dimensional array.
  </code></pre>