code: def test_2D():
      # check that a standard 2D PCA works too
      M = 100
      N = 20
      L = M - 1  # rank after mean removal
      data = np.random.uniform(size=(M, N))
      p = pca(data)
      ts = p["basis_vectors"]
      imgs = p["basis_projections"]
      assert ts.shape == (M, L)
      assert imgs.shape == (L, N)
      rimgs = reconstruct(ts, imgs)
      # add back the sqrt MSE, because we standardized
      data_mean = data.mean(0)[None, ...]
      demeaned = data - data_mean
      rmse = root_mse(demeaned, axis=0)[None, ...]
      # also add back the mean
      assert_array_almost_equal((rimgs * rmse) + data_mean, data)
      # if standardize is set, or not, covariance is diagonal
      assert diagonal_covariance(imgs)
      p = pca(data, standardize=False)
      imgs = p["basis_projections"]
      assert diagonal_covariance(imgs)
  
imports: import numpy
  import pytest
  from nipy.io.api import load_image
  from nipy.testing import assert_almost_equal, assert_array_almost_equal, funcfile
  from ..pca import pca
label_desc: Use image node_id 11 for calling a global function with example usage: test_2D() without return types