code: def _get_covariance(data, UX, rmse_scales_func, mask):
      # number of points in PCA dimension
      rank, n_pts = UX.shape
      C = np.zeros((rank, rank))
      # nan_to_num only for floating point masks
      if mask is not None:
          nan_to_num = mask.dtype.type in (
              np.sctypes["float"] + np.sctypes["complex"]
          )
      # loop over next dimension to save memory
      if data.ndim == 2:
          # If we have 2D data, just do the covariance all in one shot, by using
          # a slice that is the equivalent of the ':' slice syntax
          slices = [slice(None)]
      else:
          # If we have more then 2D, then we iterate over slices in the second
          # dimension, in order to save memory
          slices = [slice(i, i + 1) for i in range(data.shape[1])]
      for i, s_slice in enumerate(slices):
          Y = data[:, s_slice].reshape((n_pts, -1))
          # project data into required space
          YX = np.dot(UX, Y)
          if rmse_scales_func is not None:
              YX *= rmse_scales_func(Y)
          if mask is not None:
              # weight data with mask.  Usually the weights will be 0,1
              msk_slice = mask[s_slice].reshape(Y.shape[1])
              if nan_to_num:  # but if floats, check for NaNs too.
                  msk_slice = np.nan_to_num(msk_slice)
              YX = YX * msk_slice
          C += np.dot(YX, YX.T)
      return C
  
file_path: nipy/nipy/algorithms/utils/pca.py
imports: import numpy
  import numpy.linalg
  from ...core.image.image import rollimg
  from ...core.reference.coordinate_map import AxisError, drop_io_dim, io_axis_indices, orth_axes
label_desc: Use image node_id 2 for calling a global function with example usage: _get_covariance(data, UX, rmse_scales_func, mask) and returns: C