public MatrixXD Concat(MatrixXD other, ConcatType concatType) { switch (concatType) { case ConcatType.Horizontal: { var totalCols = Cols + other.Cols; double[] inputValues = new double[Rows * totalCols]; var matrixXD = new MatrixXD(inputValues, Rows, totalCols); for (int i = 0; i < Rows; i++) { for (int j = 0; j < Cols; j++) { matrixXD.Set(i, j, Get(i, j)); } } int otherCols = other.Cols; for (int i = 0; i < other.Rows; i++) { for (int j = 0; j < otherCols; j++) { matrixXD.Set(i, Cols + j, other.Get(i, j)); } } return(matrixXD); } case ConcatType.Vertical: default: { int totalRows = Rows + other.Rows; double[] inputValues = new double[totalRows * Cols]; MatrixXD matrixXD = new MatrixXD(inputValues, totalRows, Cols); for (int i = 0; i < Rows; i++) { for (int j = 0; j < Cols; j++) { matrixXD.Set(i, j, Get(i, j)); } } int otherRows = other.Rows; for (int i = 0; i < otherRows; i++) { for (int j = 0; j < Cols; j++) { matrixXD.Set(Rows + i, j, other.Get(i, j)); } } return(matrixXD); } } }
public MatrixXD Slice(int[] rows, int[] cols) { int nrows = rows.Length; int ncols = cols.Length; double[] inputValues = new double[nrows * ncols]; MatrixXD matrixXD = new MatrixXD(inputValues, nrows, ncols); for (int i = 0; i < nrows; i++) { for (int j = 0; j < ncols; j++) { matrixXD.Set(i, j, Get(rows[i], cols[j])); } } return(matrixXD); }