Spark机器学习(四) Local matrix -- Data Types

Local matrix

A local matrix has integer-typed row and column indices and double-typed values, stored on a single machine. MLlib supports dense matrices, whose entry values are stored in a single double array in column-major order, and sparse matrices, whose non-zero entry values are stored in the Compressed Sparse Column (CSC) format in column-major order. For example, the following dense matrix

局部矩阵由整数型行和列的索引和浮点数类型的值组成,存储在一个单独节点上。MLlib支持密集矩阵,entry值被存储在一个一维浮点数数组,以列为排序主键。而稀疏矩阵,non-zero entry值,以Compressed Sparse Column (CSC) 格式存储,以列主键排序。例如,下面的密集矩阵

                                                        |1.0  2.0|

                                                        |3.0  4.0|

                                                        |5.0  6.0|

                                                    

is stored in a one-dimensional array [1.0, 3.0, 5.0, 2.0, 4.0, 6.0] with the matrix size (3, 2).

被存储在一个一维数组 [1.0, 3.0, 5.0, 2.0, 4.0, 6.0]里,矩阵的size为(3,2)

Scala

The base class of local matrices is Matrix, and we provide two implementations: DenseMatrix, and SparseMatrix. We recommend using the factory methods implemented in Matrices to create local matrices. Remember, local matrices in MLlib are stored in column-major order.

局部矩阵的基类是Matrix,我们提供了两种实现:DenseMatrix, and SparseMatrix

我们推荐使用Matrices 已经实现的工厂方法来创建局部矩阵。

记住,局部矩阵在MLlib中是以列排序存储的。

Refer to the Matrix Scala docs and Matrices Scala docs for details on the API.

更多信息请参见Matrix Scala docs and Matrices Scala docs API。

import org.apache.spark.mllib.linalg.{Matrix, Matrices} 
// Create a dense matrix ((1.0, 2.0), (3.0, 4.0), (5.0, 6.0)) 
val dm: Matrix = Matrices.dense(3, 2, Array(1.0, 3.0, 5.0, 2.0, 4.0, 6.0)) 
// Create a sparse matrix ((9.0, 0.0), (0.0, 8.0), (0.0, 6.0)) 
val sm: Matrix = Matrices.sparse(3, 2, Array(0, 1, 3), Array(0, 2, 1), Array(9, 6, 8))


转载于:https://my.oschina.net/snug/blog/665103

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值