Class SparseVector

Object
org.apache.spark.ml.linalg.SparseVector
All Implemented Interfaces:
Serializable, Vector, scala.Serializable

public class SparseVector extends Object implements Vector
A sparse vector represented by an index array and a value array.

param: size size of the vector. param: indices index array, assume to be strictly increasing. param: values value array, must have the same length as the index array.

See Also:
  • Constructor Details

    • SparseVector

      public SparseVector(int size, int[] indices, double[] values)
  • Method Details

    • unapply

      public static scala.Option<scala.Tuple3<Object,int[],double[]>> unapply(SparseVector sv)
    • size

      public int size()
      Description copied from interface: Vector
      Size of the vector.
      Specified by:
      size in interface Vector
      Returns:
      (undocumented)
    • indices

      public int[] indices()
    • values

      public double[] values()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toArray

      public double[] toArray()
      Description copied from interface: Vector
      Converts the instance to a double array.
      Specified by:
      toArray in interface Vector
      Returns:
      (undocumented)
    • copy

      public SparseVector copy()
      Description copied from interface: Vector
      Makes a deep copy of this vector.
      Specified by:
      copy in interface Vector
      Returns:
      (undocumented)
    • apply

      public double apply(int i)
      Description copied from interface: Vector
      Gets the value of the ith element.
      Specified by:
      apply in interface Vector
      Parameters:
      i - index
      Returns:
      (undocumented)
    • equals

      public boolean equals(Object other)
      Specified by:
      equals in interface Vector
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Description copied from interface: Vector
      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 to java.util.Arrays.hashCode.
      Specified by:
      hashCode in interface Vector
      Overrides:
      hashCode in class Object
      Returns:
      (undocumented)
    • numActives

      public int numActives()
      Description copied from interface: Vector
      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.
      Specified by:
      numActives in interface Vector
      Returns:
      (undocumented)
    • numNonzeros

      public int numNonzeros()
      Description copied from interface: Vector
      Number of nonzero elements. This scans all active values and count nonzeros.
      Specified by:
      numNonzeros in interface Vector
      Returns:
      (undocumented)
    • argmax

      public int argmax()
      Description copied from interface: Vector
      Find the index of a maximal element. Returns the first maximal element in case of a tie. Returns -1 if vector has length 0.
      Specified by:
      argmax in interface Vector
      Returns:
      (undocumented)