Finding a good inverse for an ill-conditioned matrix transformation
The usual way to approach inverting a matrix that is rank deficient is to use a generalized inverse.

This means if your matrix equation is:
$$
y = \mathbf{A}x
$$
where $\mathbf{A}$ is an $n \times m$ matrix, then you can use, for example, the Moore-Penrose pseudo-inverse, $\mathbf{A}^{+}$:
$$
\mathbf{A}^{+} = (\mathbf{A}^*\mathbf{A})^{-1} \mathbf{A}^*
$$
if a left inverse is required or
$$
\mathbf{A}^{+} = \mathbf{A}^*(\mathbf{A}\mathbf{A}^*)^{-1}
$$
for the right inverse.

If $n=m$ then either be used.

However, as per the link above, there are many different possibilities for selecting an inverse in the rank-deficient / non-square case because the system of equations is underdetermined.

As per @MBaz's comment, you can calculate this using the singular value decomposition of $\mathbf{A}$.