Vector class
- Inheritance
-
- Object
- IterableMixin<
num> - Vector
- Implementers
- Available extensions
Constructors
- Vector.new(dynamic input, {bool isDouble = true})
- Constructs a Vector of given length with all elements initialized to 0.
- Vector.arrange(int end, {int start = 1, int step = 1})
-
Alias for Matrix.range.
factory
-
Vector.fromList(List<
num> data) - Constructs a Vector from a list of numerical values.
- Vector.linspace(int start, int end, [int number = 50])
-
Creates a row Vector with equally spaced values between the start and end values (inclusive).
factory
- Vector.random(int length, {double min = 0, double max = 1, bool isDouble = true, Random? random, int? seed})
-
Constructs a new vector of the given
length
with randomly generated values.factory - Vector.range(int end, {int start = 1, int step = 1})
-
Creates a Vector with values in the specified range, incremented by the specified step size.
factory
Properties
- direction → double
-
Available on Vector, provided by the VectorOperations extension
Returns the direction (or angle) of the vector, in radians.no setter - elements → Iterable
-
Getter to retrieve an iterable over all elements in the matrix,
regardless of their row or column.
no setter
- first → num
-
The first element.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setteroverride
- isEmpty → bool
-
Whether this collection has no elements.
no setterinherited
- isNotEmpty → bool
-
Whether this collection has at least one element.
no setterinherited
-
iterator
→ Iterator<
num> -
Overrides the iterator getter to provide a VectorIterator.
This iterator iterates over the elements of the vector.
no setteroverride
- last → num
-
The last element.
no setterinherited
- length → int
-
Returns the length (number of elements) of the vector.
no setteroverride
- magnitude → num
-
Available on Vector, provided by the VectorOperations extension
Returns the magnitude (or norm) of the vector.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- single → num
-
Checks that this iterable has only one element, and returns that element.
no setterinherited
Methods
-
abs(
) → Vector -
Available on Vector, provided by the VectorOperations extension
Returns a new vector with the absolute values of the original vector's elements. -
addMatrix(
Matrix matrix) → Matrix -
Available on Vector, provided by the VectorMatrixOperations extension
Add a vector and a matrix -
angle(
Vector other) → double -
Returns the angle (in radians) between this vector and
other
. -
any(
bool test(num element)) → bool -
Checks whether any element of this iterable satisfies
test
.inherited -
cast<
R> () → Iterable< R> -
A view of this iterable as an iterable of
R
instances.inherited -
contains(
Object? element) → bool -
Whether the collection contains an element equal to
element
.inherited -
cross(
Vector other) → Vector -
Available on Vector, provided by the VectorOperations extension
Calculates the cross product of the vector with another vector. -
distance(
Vector other, {Distance distance = Distance.frobenius}) → num -
Sets all elements of this vector to
value
. -
dot(
Vector other) → double -
Available on Vector, provided by the VectorOperations extension
Calculates the dot product of the vector with another vector. -
elementAt(
int index) → num -
Returns the
index
th element.inherited -
every(
bool test(num element)) → bool -
Checks whether every element of this iterable satisfies
test
.inherited -
exp(
) → Vector -
Available on Vector, provided by the VectorOperations extension
Returns a new vector with each element being the exponential function of the corresponding element in the original vector. -
expand<
T> (Iterable< T> toElements(num element)) → Iterable<T> -
Expands each element of this Iterable into zero or more elements.
inherited
-
firstWhere(
bool test(num element), {num orElse()?}) → num -
The first element that satisfies the given predicate
test
.inherited -
fold<
T> (T initialValue, T combine(T previousValue, num element)) → T -
Reduces a collection to a single value by iteratively combining each
element of the collection with an existing value
inherited
-
followedBy(
Iterable< num> other) → Iterable<num> -
Creates the lazy concatenation of this iterable and
other
.inherited -
forEach(
void action(num element)) → void -
Invokes
action
on each element of this iterable in iteration order.inherited -
getVector(
List< String> mapping) → Vector - Generates a new Vector (Vector2, Vector3, Vector4) based on the mapping provided.
-
innerProduct(
Vector other) → num -
Available on Vector, provided by the VectorOperations extension
Computes the inner product of two vectors. -
isUnit(
) → bool -
Returns
true
if this is a unit vector, i.e., its norm is 1. -
isZero(
) → bool -
Returns
true
if this is a zero vector, i.e., all its elements are zero. -
join(
[String separator = ""]) → String -
Converts each element to a String and concatenates the strings.
inherited
-
lastWhere(
bool test(num element), {num orElse()?}) → num -
The last element that satisfies the given predicate
test
.inherited -
map<
T> (T toElement(num e)) → Iterable< T> -
The current elements of this iterable modified by
toElement
.inherited -
mean(
) → num -
Available on Vector, provided by the VectorOperations extension
Returns the arithmetic mean of the vector. -
median(
) → num -
Available on Vector, provided by the VectorOperations extension
Returns the median value of the vector. If the vector has an even number of elements, the median is calculated as the mean of the two central elements. -
norm(
[Norm normType = Norm.frobenius]) → num -
Available on Vector, provided by the VectorOperations extension
Returns the norm (or length) of this vector. -
normalize(
[Norm normType = Norm.frobenius]) → Vector -
Available on Vector, provided by the VectorOperations extension
Returns this vector normalized. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
outerProduct(
Vector other) → Matrix -
Available on Vector, provided by the VectorOperations extension
Computes the outer product of two vectors. -
pop(
) → num - Removes the last value in the row.
-
pow(
num exponent) → Vector -
Available on Vector, provided by the VectorOperations extension
Returns a new vector with each element being raised to the provided exponent. -
product(
) → num -
Available on Vector, provided by the VectorOperations extension
Returns the product of all elements in the vector. -
projection(
Vector other) → Vector -
Returns the projection of this vector onto
other
. -
push(
num value) → void - Adds a new value at the end of the row.
-
reduce(
num combine(num value, num element)) → num -
Reduces a collection to a single value by iteratively combining elements
of the collection using the provided function.
inherited
-
rescale(
) → Vector -
Available on Vector, provided by the VectorOperations extension
Rescales the vector to the range 0-1. -
round(
[int decimalPlaces = 0]) → Vector -
Available on Vector, provided by the VectorOperations extension
Rounds each element in the vector to the specified number of decimal places. -
scale(
num scalar) → Vector -
Available on Vector, provided by the VectorOperations extension
Scales a vector by a given scalar. -
shift(
) → dynamic - Removes the first value in the row.
-
singleWhere(
bool test(num element), {num orElse()?}) → num -
The single element that satisfies
test
.inherited -
skip(
int count) → Iterable< num> -
Creates an Iterable that provides all but the first
count
elements.inherited -
skipWhile(
bool test(num value)) → Iterable< num> -
Creates an
Iterable
that skips leading elements whiletest
is satisfied.inherited -
splice(
int start, int deleteCount, [List< num> newItems = const []]) → void - Adds/removes elements at an arbitrary position in the row.
-
subtractMatrix(
Matrix matrix) → Matrix -
Available on Vector, provided by the VectorMatrixOperations extension
Subtract a matrix from a vector -
subVector(
{List< int> ? indices, String range = '', int? start, int? end}) → Vector - Extracts a subVector from the given vector using the specified indices or range.
-
sum(
) → num -
Available on Vector, provided by the VectorOperations extension
Returns the sum of all elements in the vector. -
swap(
int index1, int index2) → void - Swaps two elements in the row.
-
take(
int count) → Iterable< num> -
Creates a lazy iterable of the
count
first elements of this iterable.inherited -
takeWhile(
bool test(num value)) → Iterable< num> -
Creates a lazy iterable of the leading elements satisfying
test
.inherited -
toCylindrical(
) → List< double> - Converts the Vector from Cartesian to Cylindrical coordinates.
-
toDiagonal(
) → Matrix - Returns the leading diagonal matrix from a vector.
-
toList(
{bool growable = true}) → List< num> -
Creates a List containing the elements of this Iterable.
inherited
-
toMatrix(
int rows, int cols, {bool fillWithZeros = true}) → Matrix - Constructs a new Matrix from a vector.
-
toPolar(
) → List< double> - Converts the Vector from Cartesian to Polar coordinates.
-
toSet(
) → Set< num> -
Creates a Set containing the same elements as this iterable.
inherited
-
toSpherical(
) → List< double> - Converts the Vector from Cartesian to Spherical coordinates.
-
toString(
) → String -
Returns a string representation of (some of) the elements of
this
.override -
unShift(
num value) → void - Adds a new value at the beginning of the row.
-
where(
bool test(num element)) → Iterable< num> -
Creates a new lazy Iterable with all elements that satisfy the
predicate
test
.inherited -
whereType<
T> () → Iterable< T> -
Creates a new lazy Iterable with all elements that have type
T
.inherited
Operators
-
operator *(
dynamic other) → Vector -
Available on Vector, provided by the VectorOperations extension
-
operator +(
dynamic other) → dynamic -
Available on Vector, provided by the VectorOperations extension
-
operator -(
dynamic other) → dynamic -
Available on Vector, provided by the VectorOperations extension
-
operator /(
dynamic other) → Vector -
Available on Vector, provided by the VectorOperations extension
-
operator ==(
Object other) → bool -
The equality operator.
override
-
operator [](
int index) → num - Fetches the value at the given index of the vector.
-
operator []=(
int index, num value) → void - Sets the value at the given index of the vector.
-
operator unary-(
) → Vector -
Available on Vector, provided by the VectorOperations extension
Negates this vector element-wise.