## Class DenseVector

• All Implemented Interfaces:
Serializable

```public class DenseVector
extends Vector```
A dense vector represented by a values array.
Serialized Form
• ### Constructor Summary

Constructors
Constructor and Description
`DenseVector()`
Create a zero size vector.
`DenseVector(double[] data)`
Create a dense vector with the user provided data.
`DenseVector(int n)`
Create a size n vector with all elements zero.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`void` ```add(int i, double d)```
Add the i-th element of the vector by value "val".
`DenseVector` `append(double d)`
Create a new vector by adding an element to the end of the vector.
`DenseVector` `clone()`
`double` `dot(Vector vec)`
Compute the dot product with another vector.
`boolean` `equals(Object o)`
`double` `get(int i)`
Get the i-th element of the vector.
`double[]` `getData()`
Get the data array.
`int` `hashCode()`
`VectorIterator` `iterator()`
Get the iterator of the vector.
`DenseVector` `minus(Vector other)`
Create a new vector by subtracting another vector.
`void` `minusEqual(Vector other)`
Minus with another vector.
`void` `normalizeEqual(double p)`
Normalize the vector.
`double` `normInf()`
Return the Inf norm of the vector.
`double` `normL1()`
Return the L1 norm of the vector.
`double` `normL2()`
Return the L2 norm of the vector.
`double` `normL2Square()`
Return the square of L2 norm of the vector.
`static DenseVector` `ones(int n)`
Create a dense vector with all elements one.
`DenseMatrix` `outer()`
Compute the outer product with itself.
`DenseMatrix` `outer(DenseVector other)`
Compute the outer product with another vector.
`DenseVector` `plus(Vector other)`
Create a new vector by plussing another vector.
`void` `plusEqual(Vector other)`
Plus with another vector.
`void` ```plusScaleEqual(Vector other, double alpha)```
Plus with another vector scaled by "alpha".
`DenseVector` `prefix(double d)`
Create a new vector by adding an element to the head of the vector.
`static DenseVector` `rand(int n)`
Create a dense vector with random values uniformly distributed in the range of [0.0, 1.0].
`DenseVector` `scale(double d)`
Scale the vector by value "v" and create a new vector to store the result.
`void` `scaleEqual(double d)`
Scale the vector by value "v".
`void` ```set(int i, double d)```
Set the i-th element of the vector to value "val".
`void` `setData(double[] data)`
Set the data array.
`void` `setEqual(DenseVector other)`
Set the data of the vector the same as those of another vector.
`int` `size()`
Get the size of the vector.
`DenseVector` `slice(int[] indices)`
Slice the vector.
`void` ```standardizeEqual(double mean, double stdvar)```
Standardize the vector.
`String` `toString()`
`static DenseVector` `zeros(int n)`
Create a dense vector with all elements zero.
• ### Methods inherited from class java.lang.Object

`finalize, getClass, notify, notifyAll, wait, wait, wait`
• ### Constructor Detail

• #### DenseVector

`public DenseVector()`
Create a zero size vector.
• #### DenseVector

`public DenseVector(int n)`
Create a size n vector with all elements zero.
Parameters:
`n` - Size of the vector.
• #### DenseVector

`public DenseVector(double[] data)`
Create a dense vector with the user provided data.
Parameters:
`data` - The vector data.
• ### Method Detail

• #### getData

`public double[] getData()`
Get the data array.
• #### setData

`public void setData(double[] data)`
Set the data array.
• #### ones

`public static DenseVector ones(int n)`
Create a dense vector with all elements one.
Parameters:
`n` - Size of the vector.
Returns:
The newly created dense vector.
• #### zeros

`public static DenseVector zeros(int n)`
Create a dense vector with all elements zero.
Parameters:
`n` - Size of the vector.
Returns:
The newly created dense vector.
• #### rand

`public static DenseVector rand(int n)`
Create a dense vector with random values uniformly distributed in the range of [0.0, 1.0].
Parameters:
`n` - Size of the vector.
Returns:
The newly created dense vector.
• #### clone

`public DenseVector clone()`
Overrides:
`clone` in class `Object`
• #### toString

`public String toString()`
Overrides:
`toString` in class `Object`
• #### size

`public int size()`
Description copied from class: `Vector`
Get the size of the vector.
Specified by:
`size` in class `Vector`
• #### get

`public double get(int i)`
Description copied from class: `Vector`
Get the i-th element of the vector.
Specified by:
`get` in class `Vector`
• #### set

```public void set(int i,
double d)```
Description copied from class: `Vector`
Set the i-th element of the vector to value "val".
Specified by:
`set` in class `Vector`

```public void add(int i,
double d)```
Description copied from class: `Vector`
Add the i-th element of the vector by value "val".
Specified by:
`add` in class `Vector`
• #### normL1

`public double normL1()`
Description copied from class: `Vector`
Return the L1 norm of the vector.
Specified by:
`normL1` in class `Vector`
• #### normL2

`public double normL2()`
Description copied from class: `Vector`
Return the L2 norm of the vector.
Specified by:
`normL2` in class `Vector`
• #### normL2Square

`public double normL2Square()`
Description copied from class: `Vector`
Return the square of L2 norm of the vector.
Specified by:
`normL2Square` in class `Vector`
• #### normInf

`public double normInf()`
Description copied from class: `Vector`
Return the Inf norm of the vector.
Specified by:
`normInf` in class `Vector`
• #### slice

`public DenseVector slice(int[] indices)`
Description copied from class: `Vector`
Slice the vector.
Specified by:
`slice` in class `Vector`
• #### prefix

`public DenseVector prefix(double d)`
Description copied from class: `Vector`
Create a new vector by adding an element to the head of the vector.
Specified by:
`prefix` in class `Vector`
• #### append

`public DenseVector append(double d)`
Description copied from class: `Vector`
Create a new vector by adding an element to the end of the vector.
Specified by:
`append` in class `Vector`
• #### scaleEqual

`public void scaleEqual(double d)`
Description copied from class: `Vector`
Scale the vector by value "v".
Specified by:
`scaleEqual` in class `Vector`
• #### plus

`public DenseVector plus(Vector other)`
Description copied from class: `Vector`
Create a new vector by plussing another vector.
Specified by:
`plus` in class `Vector`
• #### minus

`public DenseVector minus(Vector other)`
Description copied from class: `Vector`
Create a new vector by subtracting another vector.
Specified by:
`minus` in class `Vector`
• #### scale

`public DenseVector scale(double d)`
Description copied from class: `Vector`
Scale the vector by value "v" and create a new vector to store the result.
Specified by:
`scale` in class `Vector`
• #### dot

`public double dot(Vector vec)`
Description copied from class: `Vector`
Compute the dot product with another vector.
Specified by:
`dot` in class `Vector`
• #### standardizeEqual

```public void standardizeEqual(double mean,
double stdvar)```
Description copied from class: `Vector`
Standardize the vector.
Specified by:
`standardizeEqual` in class `Vector`
• #### normalizeEqual

`public void normalizeEqual(double p)`
Description copied from class: `Vector`
Normalize the vector.
Specified by:
`normalizeEqual` in class `Vector`
• #### setEqual

`public void setEqual(DenseVector other)`
Set the data of the vector the same as those of another vector.
• #### plusEqual

`public void plusEqual(Vector other)`
Plus with another vector.
• #### minusEqual

`public void minusEqual(Vector other)`
Minus with another vector.
• #### plusScaleEqual

```public void plusScaleEqual(Vector other,
double alpha)```
Plus with another vector scaled by "alpha".
• #### outer

`public DenseMatrix outer()`
Description copied from class: `Vector`
Compute the outer product with itself.
Specified by:
`outer` in class `Vector`
Returns:
The outer product matrix.
• #### outer

`public DenseMatrix outer(DenseVector other)`
Compute the outer product with another vector.
Returns:
The outer product matrix.
• #### equals

`public boolean equals(Object o)`
Overrides:
`equals` in class `Object`
• #### hashCode

`public int hashCode()`
Overrides:
`hashCode` in class `Object`
• #### iterator

`public VectorIterator iterator()`
Description copied from class: `Vector`
Get the iterator of the vector.
Specified by:
`iterator` in class `Vector`