官术网_书友最值得收藏!

Matrix in Spark

A local matrix in Spark has integer-typed row and column indices. Values are double-typed. All the values are stored on a single machine. MLlib supports the following matrix types:

  • Dense matrices: Matrices where entry values stored are in a single, double array in a column-major order.
  • Sparse matrices: Matrices where non-zero entry values are stored in the CSC format in a column-major order. For example, the following dense matrix is stored in a one-dimensional array [2.0, 3.0, 4.0, 1.0, 4.0, 5.0] for the matrix size (3, 2):
2.0 3.0
4.0 1.0
4.0 5.0

This is an example of a dense and sparse matrix:

       val dMatrix: Matrix = Matrices.dense(2, 2, Array(1.0, 2.0, 3.0, 
4.0))
println("dMatrix: n" + dMatrix)

val sMatrixOne: Matrix = Matrices.sparse(3, 2, Array(0, 1, 3),
Array(0, 2, 1), Array(5, 6, 7))
println("sMatrixOne: n" + sMatrixOne)

val sMatrixTwo: Matrix = Matrices.sparse(3, 2, Array(0, 1, 3),
Array(0, 1, 2), Array(5, 6, 7))
println("sMatrixTwo: n" + sMatrixTwo)

The output of the preceding code is as follows:

     [info] Running linalg.matrix.SparkMatrix 
dMatrix:
1.0 3.0
2.0 4.0
sMatrixOne:
3 x 2 CSCMatrix
(0,0) 5.0
(2,1) 6.0
(1,1) 7.0
sMatrixTwo:
3 x 2 CSCMatrix
(0,0) 5.0
(1,1) 6.0
(2,1) 7.0
主站蜘蛛池模板: 木里| 台中市| 平遥县| 泸西县| 崇明县| 博兴县| 陵水| 瑞安市| 滕州市| 江达县| 涞源县| 海阳市| 梧州市| 伊春市| 阜阳市| 呼伦贝尔市| 和政县| 沙雅县| 望都县| 唐山市| 沙田区| 苗栗县| 黔西县| 雷山县| 资中县| 民权县| 乌兰察布市| 翼城县| 新源县| 大英县| 芜湖县| 洪江市| 彰化市| 涟水县| 泸西县| 清水河县| 师宗县| 新巴尔虎左旗| 习水县| 那坡县| 若羌县|