关注 spark技术分享,
撸spark源码 玩spark最佳实践

Vector

Vector

Vector sealed trait represents a numeric vector of values (of Double type) and their indices (of Int type).

It belongs to org.apache.spark.mllib.linalg package.

Note

To Scala and Java developers:

Vector class in Spark MLlib belongs to org.apache.spark.mllib.linalg package.

It is not the Vector type in Scala or Java. Train your eyes to see two types of the same name. You’ve been warned.

A Vector object knows its size.

A Vector object can be converted to:

  • Array[Double] using toArray.

  • a dense vector as DenseVector using toDense.

  • a sparse vector as SparseVector using toSparse.

  • (1.6.0) a JSON string using toJson.

  • (internal) a breeze vector as BV[Double] using toBreeze.

There are exactly two available implementations of Vector sealed trait (that also belong to org.apache.spark.mllib.linalg package):

  • DenseVector

  • SparseVector

Tip
Use Vectors factory object to create vectors, be it DenseVector or SparseVector.

Note
The factory object is called Vectors (plural).

赞(0) 打赏
未经允许不得转载:spark技术分享 » Vector
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏