How it works...

  1. The signature for this method constructor is:
DenseVector (double[] values)
  1. The method inherits from the following which makes its concrete methods available to all routines:
interface class java.lang.Objectinterface org.apache.spark.mllib.linalg. Vector
  1. There are several method calls that are of interest:
    1. Make a deep copy of the vector:
DenseVector copy()
    1. Convert to the SparseVector. You will do this if your vector is long and the density decreases after a number of operations (for example, zero out non-contributing members):
SparseVector toSparse()
    1. Find the number of non-zero elements. This is useful so you can convert on-the-fly to the SparseVector if the density ID is low:
Int numNonzeros()
    1. Convert ...

Get Apache Spark 2.x Machine Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.