title: Algorithm K-Means
body: <p>Friends, I hope your help, I am developing the K-Means algorithm in Java, so I have already performed for cycles to do the respective centroid operations with the Data and determine the distances, but the distances of each Centroid are in different for cycles. Now what I require is to put all those results in oneself outside the cycles. I enclose part of the code.</p>
  
  <pre><code> System.out.println("\n" + "----------" + "\n" + "Cluster K" + "\n" + "----------");
          System.out.println();
          for (int i = 0; i &lt; Datos.length; i++) {
              distanciaK = (float) Math.sqrt(Math.pow(Datos[i][0] - Datos[10][0], 2) + Math.pow(Datos[i][1] - Datos[10][1], 2) + Math.pow(Datos[i][2] - Datos[10][2], 2) + Math.pow(Datos[i][3] - Datos[10][3], 2) + Math.pow(Datos[i][4] - Datos[10][4], 2));
              System.out.println(distanciaK);
  
          }
  
          System.out.println("\n" + "----------" + "\n" + "Cluster M" + "\n" + "----------");
          System.out.println();
          for (int i = 0; i &lt; Datos.length; i++) {
              distanciaM = (float) Math.sqrt(Math.pow(Datos[i][0] - Datos[12][0], 2) + Math.pow(Datos[i][1] - Datos[12][1], 2) + Math.pow(Datos[i][2] - Datos[12][2], 2) + Math.pow(Datos[i][3] - Datos[12][3], 2) + Math.pow(Datos[i][4] - Datos[12][4], 2));
              System.out.println(distanciaM);
  
          }
  
          System.out.println();
  </code></pre>
  
  <p><strong>Code Output</strong></p>
  
  <h2>Cluster K</h2>
  
  <p>9.0
  8.485281
  9.380832
  6.3245554
  4.2426405
  3.6055512
  7.615773
  8.83176
  2.828427
  5.8309517
  0.0
  4.7958317
  5.477226
  5.196152</p>
  
  <hr>
  
  <h2>Cluster M</h2>
  
  <p>5.196152
  4.8989797
  9.486833
  6.928203
  4.8989797
  3.8729835
  7.071068
  7.071068
  3.1622777
  4.2426405
  5.477226
  6.708204
  0.0
  1.0</p>