rowVector method

Vector rowVector(
  1. int row,
  2. [bool deepCopy = true]
)

Returns a row from the matrix as a vector.

Note that by default this function returns a vector that does not shares its storage with the matrix, but allocates it's own memory. This means you can freely change the matrix after creating the vector and the vector will be unaffected.

If you wish to share the storage with the matrix for performance reasons pass deepCopy = false. This means that changes to the matrix also appear in the vector.

Example

Matrix m = Matrix([
  [1.0, 2.0, 3.0, 1.0],
  [4.0, 5.0, 6.0, 2.0],
  [7.0, 8.0, 9.0, 3.0],
]);

print( m.rowVector(1) )

prints 1.0, 2.0, 3.0, 1.0

Implementation

Vector rowVector(int row, [bool deepCopy = true]) {
  if (row < 0 || row >= this.m) {
    throw MatrixInvalidDimensions();
  }
  if (deepCopy) {
    List<double> l = List<double>.generate(this[row].length, (i) => this[row][i]);
    return Vector.row(l);
  } else {
    return Vector.row(this[row]);
  }
}