Java Matrix Transpose matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag)

Here you can find the source of matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag)

Description

First transposes a matrix, then multiplies it with another matrix that only contains elements on its diagonal (0 elswhere).

License

Open Source License

Parameter

Parameter Description
mat The matrix (m x n).
diag The matrix that only contains elements on its diagonal, as a one-dimensional vector of size n x 1 that represents the matrix of size n x n.

Return

The resulting matrix of size m x n.

Declaration

public static double[][] matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from w w w . j  av  a2  s .c  o m
     * First transposes a matrix, then multiplies it with another matrix that
     * only contains elements on its diagonal (0 elswhere).
     * @param mat The matrix (m x n).
     * @param diag The matrix that only contains elements on its diagonal, as a one-dimensional
     * vector of size n x 1 that represents the matrix of size n x n.
     * @return The resulting matrix of size m x n.
     */
    public static double[][] matrixTrans_x_diagonalMatrix(double[][] mat, double[] diag) {

        final int m = mat.length;
        final int n = mat[0].length;

        double[][] res = new double[n][m];

        for (int row = 0; row < n; row++) {
            for (int col = 0; col < m; col++) {
                res[row][col] = mat[col][row] * diag[col];
            }
        }

        return res;
    }
}

Related

  1. matrixTrans_x_diagonalMatrix_x_Matrix(double[][] mat, double[] diag)
  2. matrixTrans_x_matrix(double[][] mat)
  3. matrixTransform(Object[][] datas)
  4. matrixTranspose(Object[][] matrix)