def sparse_matrix_mean(sparse_matrix):
    """A mean calculation for sparse matrices that does not count the zero elements. 
       So it calculates the mean of the hierarchical differences over the all incoming edges"""
    if sparse_matrix.sum() == 0:
        return 0
    else:
        return sparse_matrix.sum() / float(sparse_matrix.getnnz())
