Class: Vector

Vector(elements, useClone)

Class representing a Vector and some of the possible operations.

Constructor

new Vector(elements, useClone)

Constructor of the class
Parameters:
Name Type Default Description
elements Array.<Number> | Vector Elements for initializing the vector.
useClone boolean true If true, the input array is cloned. If false, it uses the elements input directly by reference.
Source:

Methods

(static) createArray(numElements, value) → {Array.<Number>}

Creates a new array, where we can say the number of elements, and also the value used for initializing each cell of the array.
Parameters:
Name Type Description
numElements Number Number of elements.
value Number Initialization value.
Source:
Returns:
Array initialized with the given value at each cell.
Type
Array.<Number>

(static) one(numElements) → {Array.<Number>}

Creates a new array where each element value is 1.
Parameters:
Name Type Description
numElements Number Number of elements.
Source:
Returns:
Array where each cell is 1.
Type
Array.<Number>

(static) zero(numElements) → {Array.<Number>}

Creates a new array where each element value is 0.
Parameters:
Name Type Description
numElements Number Number of elements.
Source:
Returns:
Array where each cell is 0.
Type
Array.<Number>

augment(values) → {Vector}

Return a new array that is the concatenation of both.
Parameters:
Name Type Description
values Vector | Array.<Number> Vector or array to be added.
Source:
Returns:
Vector that is concat of this with values.
Type
Vector

chomp(n) → {Vector}

Returns a vector that is a subvector of this from element n.
Parameters:
Name Type Description
n Number Position of the chomp.
Source:
Returns:
Vector that is subvector of this from element n.
Type
Vector

dot(value) → {Number}

Calculates the dot product (scalar product) between two vectors.
Parameters:
Name Type Description
value Vector | Array.<Number> Vector to be multiplied by this one.
Source:
Returns:
Scalar representing the dot product.
Type
Number

elementMultiply(value) → {Vector}

Multiply this vector by the vector provided element by element.
Parameters:
Name Type Description
value Array.<Number> | Vector Vector to multiply by this one.
Source:
Returns:
Vector result of multiplication of both.
Type
Vector

forEach(fn)

Iterate every element of the vector, and executed the provided function for each one.
Parameters:
Name Type Description
fn function Function with signature (element, index).
Source:

log() → {Vector}

Return a vector where every element is the natural logarithm of the input element.
Source:
Returns:
Result vector.
Type
Vector

map(fn) → {Vector}

Creates a new vector where each element is the element of this vector, but operated by a function.
Parameters:
Name Type Description
fn function Function with signature (element, index).
Source:
Returns:
New vector result of apply the function to each element.
Type
Vector

runOperation(operand, operator)

Run an binary operation over this vector.
Parameters:
Name Type Description
operand Number | Array.<Number> | Vector Scalar o vector to operate this with.
operator Fucntion Operator binary function with signature (operandElement, thisElement, index)
Source:

subtract(value) → {Vector}

Return a new Vector that is the result of this - value.
Parameters:
Name Type Description
value Vector Vector to subtract from this one.
Source:
Returns:
Result vector that is this - value.
Type
Vector

sum() → {Number}

Returns the sum of all the elements of the Vector.
Source:
Returns:
Sum of all the vector elements.
Type
Number