Ignite - In-Memory Database and Caching Platform
org.apache.ignite.ml.math.primitives.vector

## Class VectorUtils

• ### Constructor Summary

Constructors
Constructor and Description
`VectorUtils()`
• ### Method Summary

All Methods
Modifier and Type Method and Description
`static Vector` ```copyPart(Vector v, int off, int len)```
Get copy of part of given length of given vector starting from given offset.
`static Vector` ```elementWiseMinus(Vector vec1, Vector vec2)```
Performs in-place vector subtraction.
`static Vector` ```elementWiseTimes(Vector vec1, Vector vec2)```
Performs in-place vector multiplication.
`static Vector` ```num2Vec(int num, int vecSize)```
Turn number into a local Vector of given size with one-hot encoding.
`static Vector` ```num2Vec(int num, int vecSize, boolean isDistributed)```
Turn number into Vector of given size with one-hot encoding.
`static Vector` `of(double... values)`
Creates dense local on heap vector based on array of doubles.
`static Vector` `of(Double[] values)`
Creates vector based on array of Doubles.
`static double` `vec2Num(Vector vec)`
Turn Vector into number by looking at index of maximal element in vector.
`static DenseVector` `zeroes(int n)`
Create new
`static Vector` `zeroesLike(Vector v)`
Create new vector like given vector initialized by zeroes.
`static Vector` ```zipWith(Vector v1, Vector v2, IgniteBiFunction<Double,Double,Double> f)```
Zip two vectors with given binary function (i.e. apply binary function to both vector elementwise and construct vector from results).
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### VectorUtils

`public VectorUtils()`
• ### Method Detail

• #### zeroesLike

`public static Vector zeroesLike(Vector v)`
Create new vector like given vector initialized by zeroes.
• #### zeroes

`public static DenseVector zeroes(int n)`
Create new
• #### num2Vec

```public static Vector num2Vec(int num,
int vecSize)```
Turn number into a local Vector of given size with one-hot encoding.
Parameters:
`num` - Number to turn into vector.
`vecSize` - Vector size of output vector.
Returns:
One-hot encoded number.
• #### num2Vec

```public static Vector num2Vec(int num,
int vecSize,
boolean isDistributed)```
Turn number into Vector of given size with one-hot encoding.
Parameters:
`num` - Number to turn into vector.
`vecSize` - Vector size of output vector.
`isDistributed` - Flag indicating if distributed vector should be created.
Returns:
One-hot encoded number.
• #### vec2Num

`public static double vec2Num(Vector vec)`
Turn Vector into number by looking at index of maximal element in vector.
Parameters:
`vec` - Vector to be turned into number.
Returns:
Number.
• #### elementWiseTimes

```public static Vector elementWiseTimes(Vector vec1,
Vector vec2)```
Performs in-place vector multiplication.
Parameters:
`vec1` - Operand to be changed and first multiplication operand.
`vec2` - Second multiplication operand.
Returns:
Updated first operand.
• #### elementWiseMinus

```public static Vector elementWiseMinus(Vector vec1,
Vector vec2)```
Performs in-place vector subtraction.
Parameters:
`vec1` - Operand to be changed and subtracted from.
`vec2` - Operand to subtract.
Returns:
Updated first operand.
• #### zipWith

```public static Vector zipWith(Vector v1,
Vector v2,
IgniteBiFunction<Double,Double,Double> f)```
Zip two vectors with given binary function (i.e. apply binary function to both vector elementwise and construct vector from results). Example zipWith({0, 2, 4}, {1, 3, 5}, plus) = {0 + 1, 2 + 3, 4 + 5}. Length of result is length of shortest of vectors.
Parameters:
`v1` - First vector.
`v2` - Second vector.
`f` - Function to zip with.
Returns:
Result of zipping.
• #### copyPart

```public static Vector copyPart(Vector v,
int off,
int len)```
Get copy of part of given length of given vector starting from given offset.
Parameters:
`v` - Vector to copy part from.
`off` - Offset.
`len` - Length.
Returns:
Copy of part of given length of given vector starting from given offset.
• #### of

`public static Vector of(double... values)`
Creates dense local on heap vector based on array of doubles.
Parameters:
`values` - Values.
• #### of

`public static Vector of(Double[] values)`
Creates vector based on array of Doubles. If array contains null-elements then method returns sparse local on head vector. In other case method returns dense local on heap vector.
Parameters:
`values` - Values.