code: public static void byMagnitude(Matrix m) {
          double totalMag = 0;
          for (int i = 0; i < m.rows(); ++i) {
              for (int j = 0; j < m.columns(); ++j) {
                  totalMag += Math.pow(m.get(i, j), 2);
              }
          }
          totalMag = Math.sqrt(totalMag);
  
          // Skip normalization if the l2 norm is 0.
          if (totalMag == 0d)
              return;
          for (int i = 0; i < m.rows(); ++i) {
              for (int j = 0; j < m.columns(); ++j) {
                  m.set(i, j, m.get(i, j) / totalMag);
              }
          }
      }
docs: Normalize the all the values values in the {@code Matrix} to be
  normalized by the l2 norm of the entire {@code Matrix}.
  
  @param m The matrix to normalize.