addVectorToEachColumn static method

Matrix addVectorToEachColumn(
  1. Matrix matrix,
  2. Matrix column
)

Return copy of matrix where each column where added by column

Implementation

static Matrix addVectorToEachColumn(Matrix matrix, Matrix column) {
  if (column.m == 1 && matrix.n == column.n) {
    Matrix resultMatrix = Matrix.zero(n: matrix.n, m: matrix.m);
    for (int i = 0; i < resultMatrix.n; i += 1) {
      for (int j = 0; j < resultMatrix.m; j += 1) {
        resultMatrix[i][j] = matrix[i][j] + column[i][0];
      }
    }
    return resultMatrix;
  } else {
    throw Exception('Dimensions error: A.shape != B.shape');
  }
}