【发布时间】:2016-03-07 05:05:12
【问题描述】:
我是 Java 新手, 目前,我正在练习一些 Java 代码。所以我正在尝试自己构建一个 Matrix 类。但是,我参考了 jama (http://math.nist.gov/javanumerics/jama/doc/Jama/Matrix.html) 的代码。 但我觉得这很奇怪。这是Matrix类的结构,Jama在后面定义。
谁能帮我解释一下为什么transpose()返回X(在我看来,C数组是X的转置元素,X的元素是相同的顺序。但是为什么jama返回X,以及C数组的作用是什么?在这个程序中?)。 非常感谢。
public class Matrix
{
private double[][] A;// 2-D array to hold matrix element
private m,n ; // number of column and row.
// Some constructors but I would like to omit
//public methods:
// I don't understand this:
public Matrix transpose () {
Matrix X = new Matrix(n,m);
double[][] C = X.getArray();
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
C[j][i] = A[i][j];
}
}
return X; // While it returns X? seem that X does not transpose but C.
// it seems there is no connection between X and C. what is the role of C here?
}
public double[][] getArray () {
return A;
}
}
【问题讨论】: