public static double[][] transposeTimes(final double[][] m1, final double[][] m2) {
    final int rowdim1 = m1.length, coldim1 = getColumnDimensionality(m1);
    final int coldim2 = getColumnDimensionality(m2);
    assert m2.length == rowdim1 : ERR_MATRIX_INNERDIM;
    final double[][] re = new double[coldim1][coldim2];
    final double[] Bcolj = new double[rowdim1];
    for(int j = 0; j < coldim2; j++) {
      // Make a linear copy of column j from B
      for(int k = 0; k < rowdim1; k++) {
        Bcolj[k] = m2[k][j];
      }
      // multiply it with each row from A
      for(int i = 0; i < coldim1; i++) {
        double s = 0;
        for(int k = 0; k < rowdim1; k++) {
          s += m1[k][i] * Bcolj[k];
        }
        re[i][j] = s;
      }
    }
    return re;
  }
public static double [ ] [ ] transposeTimes ( final double [ ] [ ] m1 , final double [ ] [ ] m2 ) { final int rowdim1 = m1 . length , coldim1 = getColumnDimensionality ( m1 ) ; final int coldim2 = getColumnDimensionality ( m2 ) ; assert m2 . length == rowdim1 : ERR_MATRIX_INNERDIM ; final double [ ] [ ] re = new double [ coldim1 ] [ coldim2 ] ; final double [ ] Bcolj = new double [ rowdim1 ] ; for ( int j = 0 ; j < coldim2 ; j ++ ) { for ( int k = 0 ; k < rowdim1 ; k ++ ) { Bcolj [ k ] = m2 [ k ] [ j ] ; } for ( int i = 0 ; i < coldim1 ; i ++ ) { double s = 0 ; for ( int k = 0 ; k < rowdim1 ; k ++ ) { s += m1 [ k ] [ i ] * Bcolj [ k ] ; } re [ i ] [ j ] = s ; } } return re ; }
Matrix multiplication, m1<sup>T</sup> * m2

@param m1 Input matrix
@param m2 another matrix
@return Matrix product, m1<sup>T</sup> * m2