code: public static EntropyStats entropy(SparseMatrix m) {
          double sum = 0;
          double[] colSums = new double[m.columns()];
          double[] rowSums = new double[m.rows()];
          for (int r = 0; r < m.rows(); ++r) {
              SparseDoubleVector sv = m.getRowVector(r);
              for (int c : sv.getNonZeroIndices()) {
                  double v = m.get(r, c);
                  sum += v;
                  colSums[c] += v;
                  rowSums[r] += v;
              }
          }
  
          double entropy = 0;
          double[] colEntropy = new double[m.columns()];
          double[] rowEntropy = new double[m.rows()];
          for (int r = 0; r < m.rows(); ++r) {
              SparseDoubleVector sv = m.getRowVector(r);
              for (int c : sv.getNonZeroIndices()) {
                  double v = m.get(r, c);
                  entropy -= entropy(v, sum);
                  colEntropy[c] -= entropy(v, colSums[c]);
                  rowEntropy[r] -= entropy(v, rowSums[r]);
              }
          }
          return new EntropyStats(entropy, colEntropy, rowEntropy);
      }
docs: Returns a {@link EntropyStats} covering the entropies of all joint events,
  rows, and columns in {@code m}.