Here you can find the source of transposeQuad(final double[][] src, int n)
Parameter | Description |
---|---|
src | the quadratic <tt>n</tt>-by-<tt>n</tt> matrix to be transposed |
n | size of the matrix |
public static double[][] transposeQuad(final double[][] src, int n)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w .j a v a2 s .c om * Transposes the given quadratic matrix. * * @param src * the quadratic <tt>n</tt>-by-<tt>n</tt> matrix to be transposed * @param n * size of the matrix * @return a new <tt>n</tt>-by-<tt>n</tt> matrix, * transpose of src */ public static double[][] transposeQuad(final double[][] src, int n) { assert hasShape(src, n, n); final double[][] dest = new double[n][n]; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { dest[i][j] = src[j][i]; dest[j][i] = src[i][j]; } } return dest; } /** * Returns whether matrix mat has size l1-by-l2 or not * @param mat a matrix * @param l1 first dimension (lines) * @param l2 second dimension (columns) * @return */ public static boolean hasShape(final double[][] mat, int l1, int l2) { assert mat != null; assert l1 > 0; assert l2 > 0; if (mat.length != l1) { return false; } for (int i = 0; i < mat.length; i++) { if (mat[i].length != l2) { return false; } } return true; } public static boolean hasShape(final double[][][] mat3d, int l1, int l2, int l3) { assert mat3d != null; assert l1 > 0; assert l2 > 0; assert l3 > 0; if (mat3d.length != l1) { return false; } for (int i = 0; i < mat3d.length; i++) { if (mat3d[i].length != l2) { return false; } for (int j = 0; j < mat3d[i].length; j++) { if (mat3d[i][j].length != l3) { return false; } } } return true; } }