Computes a generalized sweep inverse.


xig = invswp(x)#

x (NxN matrix) – data


xig (NxN matrix) – the generalized inverse of x.


This will invert any general matrix. That is, even matrices which will not invert using inv() because they are singular will invert using invswp().

x and xig will satisfy the two conditions:

  1. \(x*xig*x = x\)

  2. \(xig*x*xig = y\)

invswp() returns a row and column with zeros when the pivot fails. This is good for quadratic forms since it essentially removes rows with redundant information, i.e., the statistics generated will be “correct” but with reduced degrees of freedom.

The tolerance used to determine if a pivot element is zero is taken from the crout() singularity tolerance. The corresponding row and column are zeroed out. See Singularity Tolerance.