class MatrixUtils {

  public static double computeSparseness(DoubleMatrix2D A) {
    int count = 0;

    for (int r = 0; r < A.rows(); r++) {
      for (int c = 0; c < A.columns(); c++) {
        if (A.getQuick(r, c) != 0) {
          count++;
        }
      }
    }

    return count / (double) (A.rows() * A.columns());
  }

}