# matrices – Generation of a sparse Hermitian matrix in Python

I would like to find a way to generate Hermitian sparse matrices in Python, but I do not really know how to do it effectively. How could I do it?

Obviously, there are slow and ugly ways to do this, but as I will do it often, I would like it if there was a faster way to do it.

Is there an easy way to calculate the density of the matrix? This is the parameter I would use to compare two factorization algorithms. This is defined as
$$d = frac { mathrm {nnn}} {n ^ 2}$$
or $$mathrm {nnz}$$ is defined as the number of non-zero entries in the matrix and $$n$$ is its number of rows or columns (from where $$n ^ 2$$ is the number of elements in the matrix).