Class DenseVector
java.lang.Object
org.la4j.Vector
org.la4j.vector.DenseVector
- Direct Known Subclasses:
BasicVector
A dense vector.
A vector represents an array of elements. It can be re-sized.
A dense data structure usually stores data in an underlying array. Zero elements
take up memory space. If you want a data structure that will not have zero
elements take up memory space, try a sparse structure.
However, fetch/store operations on dense data structures only take O(1) time,
instead of the O(log n) time on sparse structures.
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<T> Tapply(VectorMatrixOperation<T> operation, Matrix that) Pipes this vector to a givenoperation.<T> Tapply(VectorOperation<T> operation) Pipes this vector to a givenoperation.<T> Tapply(VectorVectorOperation<T> operation, Vector that) Pipes this vector to a givenoperation.static DenseVectorconstant(int length, double value) static DenseVectorfromArray(double[] array) Creates a newDenseVectorfrom the givenarrayw/o copying the underlying array.static DenseVectorfromCollection(Collection<? extends Number> list) Creates newDenseVectorfromstatic DenseVectorParsesDenseVectorfrom the given CSV string.static DenseVectorCreates newDenseVectorfrom index-value mapstatic DenseVectorParsesDenseVectorfrom the given Matrix Market string.static DenseVectorabstract double[]toArray()Converts this dense vector to a double array.Converts this vector to matrix with only one column.Converts this vector to a diagonal matrix.toMatrixMarket(NumberFormat formatter) Converts this vector into the string in Matrix Market format using the givenformatter;Converts this vector to matrix with only one row.static DenseVectorunit(int length) Creates an unitDenseVectorof the givenlength.static DenseVectorzero(int length) Creates a zeroDenseVectorof the givenlength.Methods inherited from class Vector
add, add, blank, blankOfLength, copy, copyOfLength, divide, each, ensureLengthIsCorrect, equals, equals, euclideanNorm, fail, fold, get, hadamardProduct, hashCode, infinityNorm, innerProduct, is, iterator, length, manhattanNorm, max, min, mkString, mkString, multiply, multiply, non, norm, outerProduct, product, select, set, setAll, shuffle, slice, sliceLeft, sliceRight, subtract, subtract, sum, swapElements, to, toBinary, toCSV, toCSV, toDenseVector, toMatrixMarket, toSparseVector, toString, transform, update, updateAtMethods inherited from interface Iterable
forEach, spliterator
-
Constructor Details
-
DenseVector
public DenseVector(int length)
-
-
Method Details
-
zero
Creates a zeroDenseVectorof the givenlength. -
constant
-
unit
Creates an unitDenseVectorof the givenlength. -
random
-
fromArray
Creates a newDenseVectorfrom the givenarrayw/o copying the underlying array. -
fromCSV
ParsesDenseVectorfrom the given CSV string.- Parameters:
csv- the CSV string representing a vector- Returns:
- a parsed vector
-
fromMatrixMarket
ParsesDenseVectorfrom the given Matrix Market string.- Parameters:
mm- the string in Matrix Market format- Returns:
- a parsed vector
-
fromCollection
Creates newDenseVectorfrom- Parameters:
list- list containing doubles- Returns:
- new vector from given double list
-
fromMap
Creates newDenseVectorfrom index-value map- Parameters:
map- index-value maplength- vector length- Returns:
- created vector
-
apply
Description copied from class:VectorPipes this vector to a givenoperation. -
apply
Description copied from class:VectorPipes this vector to a givenoperation. -
apply
Description copied from class:VectorPipes this vector to a givenoperation.- Specified by:
applyin classVector- Type Parameters:
T- the result type- Parameters:
operation- the vector-matrix operation (an operation that takes vector and matrix and returnsT)that- the right hand matrix for the given operation- Returns:
- the result of an operation applied to this vector and
thatmatrix
-
toArray
public abstract double[] toArray()Converts this dense vector to a double array.- Returns:
- an array representation of this vector
-
toRowMatrix
Description copied from class:VectorConverts this vector to matrix with only one row.- Specified by:
toRowMatrixin classVector- Returns:
- the row matrix
-
toColumnMatrix
Description copied from class:VectorConverts this vector to matrix with only one column.- Specified by:
toColumnMatrixin classVector- Returns:
- the column matrix
-
toDiagonalMatrix
Description copied from class:VectorConverts this vector to a diagonal matrix.- Specified by:
toDiagonalMatrixin classVector- Returns:
- a diagonal matrix
-
toMatrixMarket
Description copied from class:VectorConverts this vector into the string in Matrix Market format using the givenformatter;- Specified by:
toMatrixMarketin classVector- Parameters:
formatter- the number formater- Returns:
- a Matrix Market string representing this vector
-