本文介绍了如何在Java中获取矩阵/数组的转置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个矩阵A,我必须键入什么才能得到A的转置矩阵? (让我们说B)

Assume I have a matrix A.What do I have to type to get the transposed matrix of A? (lets say B)

(我已经在项目中导入了Apache Commons Math,我想使用这些库来实现)

我的代码是:

double[][] A = new double[2][2];
        A[0][0] = 1.5;
        A[0][1] = -2.0;
        A[1][0] = 7.3;
        A[1][1] = -13.5;

那又怎样?...

(我找到了此链接,但我不知道该怎么做:

(I have found this link, but I don't know what exactly to do:

http://commons.apache.org/proper/commons-math/apidocs/org/apache/commons/math3/linear/RealMatrix.html

我尝试过:

double[][] a = new double[2][2];
a = RealMatrix.transpose();

double[][] a = new double[2][2];
a = A.transpose();

又如何以相同的方式转置数组?

And how can I transpose an array a in the same way?

推荐答案

double[][] matrixData = { {1.5d,2d}, {7.3d,-13.5d}};
RealMatrix m = MatrixUtils.createRealMatrix(matrixData);

有一种称为转置"的方法,该方法返回矩阵的转置

There is a method called transpose that returns the transpose of the matrix

RealMatrix m1=m.transpose();

m1是m的转置

这篇关于如何在Java中获取矩阵/数组的转置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 23:19