Java Matrix Transpose transpose(final double[][] A)

Here you can find the source of transpose(final double[][] A)

Description

transpose

License

Apache License

Parameter

Parameter Description
A a parameter

Declaration

public static final double[][] transpose(final double[][] A) 

Method Source Code

//package com.java2s;
/**/*from   w  w  w . j  a  v a2 s.  c  o  m*/
 * Copyright (C) 2012 Fredrik Ekelund <fredrik@ipx.se>
 *
 * This file is part of Decision Trees.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * 
     * @param A
     * @return
     */
    public static final double[][] transpose(final double[][] A) {
        final int m = A.length;
        final int n = m > 0 ? A[0].length : 0;
        final double[][] aT = new double[n][m];
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                aT[j][i] = A[i][j];
            }
        }

        return aT;
    }

    /**
     * 
     * @param a
     * @return
     */
    public static final double[][] transpose(final double[] a) {
        final int m = a.length;
        final double[][] aT = new double[m][1];
        for (int i = 0; i < m; i++) {
            aT[i][0] = a[i];
        }

        return aT;
    }
}

Related

  1. transpose(double[][] arr)
  2. transpose(double[][] ary)
  3. transpose(double[][] in)
  4. transpose(double[][] matrix)
  5. transpose(double[][] matrix)
  6. transpose(final double[][] m)
  7. transpose(final double[][] original)
  8. transpose(final double[][] src, final double[][] dest, int l1, int l2)
  9. transpose(float[] mat, float[] dest)