Package org.apache.spark.ml.linalg
Interface Vector
- All Superinterfaces:
- Serializable
- All Known Implementing Classes:
- DenseVector,- SparseVector
Represents a numeric vector, whose index type is Int and value type is Double.
 
- Note:
- Users should not implement this interface.
- 
Method SummaryModifier and TypeMethodDescriptionReturns an iterator over all the active elements of this vector.doubleapply(int i) Gets the value of the ith element.intargmax()Find the index of a maximal element.breeze.linalg.Vector<Object>asBreeze()Converts the instance to a breeze vector.Returns a vector in either dense or sparse format, whichever uses less storage.compressedWithNNZ(int nnz) copy()Makes a deep copy of this vector.doubleCalculate the dot product of this vector with another.booleanvoidApplies a functionfto all the elements of dense and sparse vector.voidforeachActive(scala.Function2<Object, Object, scala.runtime.BoxedUnit> f) Applies a functionfto all the active elements of dense and sparse vector.voidforeachNonZero(scala.Function2<Object, Object, scala.runtime.BoxedUnit> f) Applies a functionfto all the non-zero elements of dense and sparse vector.longinthashCode()Returns a hash code value for the vector.iterator()Returns an iterator over all the elements of this vector.Returns an iterator over all the non-zero elements of this vector.intNumber of active entries.intNumber of nonzero elements.intsize()Size of the vector.double[]toArray()Converts the instance to a double array.toDense()Converts this vector to a dense vector.toSparse()Converts this vector to a sparse vector with all explicit zeros removed.toSparseWithSize(int nnz) Converts this vector to a sparse vector with all explicit zeros removed when the size is known.
- 
Method Details- 
activeIteratorReturns an iterator over all the active elements of this vector.- Returns:
- (undocumented)
 
- 
applydouble apply(int i) Gets the value of the ith element.- Parameters:
- i- index
- Returns:
- (undocumented)
 
- 
argmaxint argmax()Find the index of a maximal element. Returns the first maximal element in case of a tie. Returns -1 if vector has length 0.- Returns:
- (undocumented)
 
- 
asBreezebreeze.linalg.Vector<Object> asBreeze()Converts the instance to a breeze vector.- Returns:
- (undocumented)
 
- 
compressedVector compressed()Returns a vector in either dense or sparse format, whichever uses less storage.- Returns:
- (undocumented)
 
- 
compressedWithNNZ
- 
copyVector copy()Makes a deep copy of this vector.- Returns:
- (undocumented)
 
- 
dotCalculate the dot product of this vector with another.If sizedoes not match anIllegalArgumentExceptionis thrown.- Parameters:
- v- (undocumented)
- Returns:
- (undocumented)
 
- 
equals
- 
foreachApplies a functionfto all the elements of dense and sparse vector.- Parameters:
- f- the function takes two parameters where the first parameter is the index of the vector with type- Int, and the second parameter is the corresponding value with type- Double.
 
- 
foreachActiveApplies a functionfto all the active elements of dense and sparse vector.- Parameters:
- f- the function takes two parameters where the first parameter is the index of the vector with type- Int, and the second parameter is the corresponding value with type- Double.
 
- 
foreachNonZeroApplies a functionfto all the non-zero elements of dense and sparse vector.- Parameters:
- f- the function takes two parameters where the first parameter is the index of the vector with type- Int, and the second parameter is the corresponding value with type- Double.
 
- 
getSizeInByteslong getSizeInBytes()
- 
hashCodeint hashCode()Returns a hash code value for the vector. The hash code is based on its size and its first 128 nonzero entries, using a hash algorithm similar tojava.util.Arrays.hashCode.
- 
iteratorReturns an iterator over all the elements of this vector.- Returns:
- (undocumented)
 
- 
nonZeroIteratorReturns an iterator over all the non-zero elements of this vector.- Returns:
- (undocumented)
 
- 
numActivesint numActives()Number of active entries. An "active entry" is an element which is explicitly stored, regardless of its value. Note that inactive entries have value 0.- Returns:
- (undocumented)
 
- 
numNonzerosint numNonzeros()Number of nonzero elements. This scans all active values and count nonzeros.- Returns:
- (undocumented)
 
- 
sizeint size()Size of the vector.- Returns:
- (undocumented)
 
- 
toArraydouble[] toArray()Converts the instance to a double array.- Returns:
- (undocumented)
 
- 
toDenseDenseVector toDense()Converts this vector to a dense vector.- Returns:
- (undocumented)
 
- 
toSparseSparseVector toSparse()Converts this vector to a sparse vector with all explicit zeros removed.- Returns:
- (undocumented)
 
- 
toSparseWithSizeConverts this vector to a sparse vector with all explicit zeros removed when the size is known. This method is used to avoid re-computing the number of non-zero elements when it is already known. This method should only be called after computing the number of non-zero elements vianumNonzeros(). e.g.val nnz = numNonzeros val sv = toSparse(nnz)If nnzis under-specified, aArrayIndexOutOfBoundsExceptionis thrown.- Parameters:
- nnz- (undocumented)
- Returns:
- (undocumented)
 
 
-