columnBind static method

Matrix columnBind(
  1. Matrix a,
  2. Matrix b
)

Return Matrix created as binded a and b by columns. Elements of a set first, and elements of b second

Example:

final a = Matrix.column([0,0,0]);
final b = Matrix.column([1,1,1]);
final matrix = MatrixOperation.columnBind(a, b);
print(matrix);
// Output:
// matrix 3тип2
// [[0.0, 1.0]
// [0.0, 1.0]
// [0.0, 1.0]]

Throw an exception if dimensions condition is not met

Implementation

static Matrix columnBind(Matrix a, Matrix b) {
  if (a.n == b.n) {
    var resultMatrix = Matrix.zero(n: a.n, m: a.m + b.m);
    for (int i = 0; i < resultMatrix.n; i += 1) {
      for (int j = 0; j < resultMatrix.m; j += 1) {
        resultMatrix[i][j] = j < a.m ? a[i][j] : b[i][j - a.m];
      }
    }
    return resultMatrix;
  } else {
    throw Exception('Dimensions error: A.n != B.n');
  }
}