Vector class

The Vector class

Most of the class code is not optimized for high performance but for readability. You should be able to read the functions and understand what is going on with basic linear algebra knowledge.

The vector can be either a row or column vector. More reading about vectors

final Matrix a = Matrix([[1, 2], [3, 4]]);
final Vector b = Vector.column([2, 3]);
final Matrix e = Matrix([[8], [18]]);
Matrix result = a * b;
print(result == e);

This prints

[[8.0], [18.0]]


Vector.column(List<double> values)
Creates a column vector from the list of values given. [...]
Vector.fillColumn(int count, [ double fill = 0.0 ])
Creates a column vector with count elements filled with fill [...]
Vector.fillRow(int count, [ double fill = 0.0 ])
Creates a row vector with count elements filled with fill [...]
Vector.fromMatrix(Matrix matrix)
Converts a Matrix to a Vector if one of its dimensions is 1 will throw MatrixInvalidDimensions if that is not the case.
Vector.row(List<double> values)
Creates a row vector from the list of values given. [...]


elements → int
Returns the number of elements in the vector.
hashCode → int
Returns the hashCode for the matrix.
type VectorType
Returns the VectorType of the vector.
runtimeType → Type
A representation of the runtime type of the object.
read-only, inherited


crossProduct(Vector other) Vector
Calculates the cross product for two 3-dimensional vectors. [...]
dotProduct(Vector other) → double
Calculates the dot product for two 3-dimensional vectors. [...]
magnitude() → double
Returns the magnitude, length or Euclidean norm of the vector. [...]
manhattanNorm() → double
Returns the Manhattan norm of the vector. [...]
map(MatrixMapFunc f) Vector
Maps this Vector via function f to a new Vector. [...]
mean() → double
Returns element wise mean of the vector. [...]
norm() → double
Returns the Euclidean norm of the vector. [...]
normalize() Vector
Normalizes this Vector to have magnitude 1.0 [...]
sum() → double
Returns element wise sum of the vector. [...]
toList([bool deepCopy = true ]) → List<double>
Returns the List<double> of this Vector [...]
toMatrix([bool deepCopy = true ]) Matrix
Returns the Matrix representation of this Vector [...]
toString() → String
Prints the content of the matrix.
transpose() Vector
Transposes a Vector from row or column to column or row. [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed.


operator *(dynamic other) Matrix
Multiplies two vectors, note the return value is a Matrix. If you need a scalar result add 0, and if you need the Vector result add .toVector() [...]
operator +(Vector other) Vector
Adds two vectors [...]
operator -(Vector other) Vector
Subtracts two vectors [...]
operator ==(dynamic other) → bool
Returns true if the vectors are the same ( or close with 1e-9 relative )
operator [](int element) → double
Access the element's value in the vector. [...]
operator []=(int element, double value) → void
Write values to elements of the vector.
operator ~() Vector
Negate all values [...]