code: def pca(data, components):
      """
      Finds the `components` top principal components of the data.
      """
      assert components > 0 and components < data.size(
          1
      ), "incorrect # of PCA dimensions"
      # We switch to numpy here as torch.symeig gave strange results.
      dtype = data.dtype
      data = data.numpy()
      data -= np.mean(data, axis=0, keepdims=True)
      cov = np.cov(data.T)
      L, V = nla.eigh(cov)
      return torch.tensor(V[:, -components:], dtype=dtype)
  
file_path: CrypTen/examples/util.py
imports: import logging
  import os
  import numpy
  import numpy.linalg
  import torch
label_desc: Use image node_id 4 for calling a global function with example usage: pca(data, components) and returns: torch