确定向量数组长度

时间:2016-03-07 09:17:29

标签: java

public class Matrix {
  public static int a = 0;
  public static int b = 0;

  public double myArray[][];

  public Matrix(double a[][]) {
    this.myArray = a;
  }

  public Matrix(int b, Vector... vectors) {

    double myArray[][] = new double[vectors.length][];

    int row = vectors.length;
    Matrix.a = row;
    int column = vectors[0].getYourArray().length;
    Matrix.b = column;
    for (int i = 0; i < row; i++) {
      myArray[i] = new double[row];
    }
    for (int i = 0; i < row; i++) {
      for (int j = 0; j < column; j++) {
        if (b == 0) {
          double[] a = vectors[i].getYourArray();
          myArray[i][j] = a[j];

        } else {
          myArray[j][i] = vectors[i].getYourArray()[j];
        }
      }
    }
  }

  public class Vector {

    double yourArray[];

    public double[] getYourArray() {
      return yourArray;
    }

    public void setYourArray(double[] yourArray) {
      this.yourArray = yourArray;
    }

    public Vector(double... yourArray) {
      this.yourArray = yourArray;
    }
  }
}

我创建了2个向量数组并将它们发送到向量类中,以创建一个包含这两个向量参数的数组,然后发送到矩阵类以创建具有向量数组维度的矩阵

问题在于我如何确定新矩阵的行和列?

我无法写出正确的代码,请帮帮我

1 个答案:

答案 0 :(得分:1)

正如您在代码中看到的那样:

  • 第1维:vectors.length
  • 第二维:vectors[0].getYourArray().length

通常你还必须确保,对于所有vectors[0].getYourArray(),长度是相同的。