# Moore-Penrose Generalized Inverse of Sparse Matrix

**URL:** <https://discourse.julialang.org/t/moore-penrose-generalized-inverse-of-sparse-matrix/17414>\
**Category:** Optimization (Mathematical)\
**Created:** [November 11, 2018, 11:05pm UTC](https://discourse.julialang.org/t/moore-penrose-generalized-inverse-of-sparse-matrix/17414 "2018-11-11T23:05:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_McVay](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_mcvay/32/4307_2.png) [@Paul\_McVay](https://discourse.julialang.org/u/Paul_McVay)\
**Post date:** [November 11, 2018, 11:05pm UTC](https://discourse.julialang.org/t/moore-penrose-generalized-inverse-of-sparse-matrix/17414/1 "2018-11-11T23:05:51Z")

</div>

Is there any package that provides a function to calculate a generalized inverse of a sparse matrix? I know the `LinearAlgebra` package provides `pinv` and the `SparseArrays` provides capabilities for the creation of sparse matrices but have not been able to find any the calculate the psuedo-inverse of a sparse matrix

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 11, 2018, 11:40pm UTC](https://discourse.julialang.org/t/moore-penrose-generalized-inverse-of-sparse-matrix/17414/2 "2018-11-11T23:40:04Z")

</div>

The pseudo-inverse of a sparse matrix would almost always be dense, wouldn’t it? Given that, it seems like it doesn’t make too much sense to have a sparse pinv—or if one does it would be equivalent to converting to sense first.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [November 12, 2018, 3:01am UTC](https://discourse.julialang.org/t/moore-penrose-generalized-inverse-of-sparse-matrix/17414/3 "2018-11-12T03:01:46Z")

</div>

You almost never compute the inverse (pseudo or otherwise) of a sparse matrix because the inverse is generally dense.

On the other hand, you do compute the _application_ of the inverse to a vector, and you often precompute factorizations that let you apply the inverse more quickly.

In the case of the ordinary inverse, you can apply a sparse inverse with `A \ b` and compute the factorization with `lu(A)` etcetera. In the case of the pseudoinverse, applying it computes the least-squares solution, and the corresponding factorization is usually `qr`.
