1. 程式人生 > >Spark MLlib 入門--Breeze函式

Spark MLlib 入門--Breeze函式

1、建立0向量
scala> val v1 = DenseVector.zeros[Double](3)
v1: breeze.linalg.DenseVector[Double] = DenseVector(0.0, 0.0, 0.0)
2、建立單位向量
scala> val v2 = DenseVector.ones[Double](3)
v2: breeze.linalg.DenseVector[Double] = DenseVector(1.0, 1.0, 1.0)
3、數字填充向量
scala> val v3=DenseVector.fill(3){5}
v3: breeze.linalg.DenseVector[Int] = DenseVector(5, 5, 5)
4、邊界步長向量
scala> val v4=DenseVector.range(1,10,2)
v4: breeze.linalg.DenseVector[Int] = DenseVector(1, 3, 5, 7, 9)
5、對角陣
scala> val v5=diag(DenseVector(1,2,3))
v5: breeze.linalg.DenseMatrix[Int] =
1  0  0
0  2  0
0  0  3
6、建立一般行向量
scala> val v6=DenseVector(1,2,3,4)
v6: breeze.linalg.DenseVector[Int] = DenseVector(1, 2, 3, 4)
7、建立一般列向量
scala> val v7=DenseVector(1,1,1,1).t
v7: breeze.linalg.Transpose[breeze.linalg.DenseVector[Int]] = Transpose(DenseVector(1, 1, 1, 1))
8、建立指定維數的隨機向量
scala> val v8=DenseVector.rand(3)
v8: breeze.linalg.DenseVector[Double] = DenseVector(0.4516977975198784, 0.7437508243707496, 0.7636911432772242)