title: Principal Component Analysis converts 3d array to 1d array using Python
body: <p>I have the following input data <code>[-5, 10,2], [-2, -3,3], [-4, -9,1], [7, 11,-3], [12, 6,-1], [13, 4,5]</code> on hand and would like to use PCA to convert from 3D array to 1D array. I typed with the following code:</p>
  
  <pre><code>import numpy as np
  input = np.array([[-5, 10,2], [-2, -3,3], [-4, -9,1], [7, 11,-3], [12, 6,-1], [13, 4,5]]) 
  mean_x = np.mean(input[0,:])
  mean_y = np.mean(input[1,:])
  mean_z = np.mean(input[2,:])
  scaled_vector = np.array([input[0,:]-[mean_x],input[1,:]-[mean_y],input[2,:]-[mean_z]])
  data=np.vstack((scaled_vector)).T
  scatter_matrix=np.dot(np.transpose(data),data)
  eig_val, eig_vec = np.linalg.eig(scatter_matrix)
  eig_pairs = [(np.abs(eig_val[i]), eig_vec[:,i]) for i in range(len(eig_val))]
  eig_pairs.sort(reverse=True)
  feature=eig_pairs[0][1][2]
  new_data_reduced=np.dot(data,np.transpose(feature))
  print(new_data_reduced)
  </code></pre>
  
  <p>I also use the <code>sklearn.decomposition import PCA</code> to do as verification.</p>
  
  <pre><code>import numpy as np
  from sklearn.decomposition import PCA
  X = np.array([[-5, 10,2], [-2, -3,3], [-4, -9,1], [7, 11,-3], [12, 6,-1], [13, 4,5]]) 
  pca = PCA(n_components=1)
  pca.componrnt = True
  newX = pca.fit_transform(X)
  print (newX)
  </code></pre>
  
  <p>The results from <code>sklearn</code> is </p>
  
  <pre><code>[[  1.81922968]
   [  8.34080915]
   [ 13.64517202]
   [ -8.17114609]
   [ -8.37254693]
   [ -7.26151783]]
  </code></pre>
  
  <p>I am not sure if this results is correct or not. However, when I use my own PCA, I find that the results are extremely different. Therefore, how can I correct it?</p>