特殊语法学习

1、rdd.filter(x => (20170720 to 20170807).exists(t => x(5).startsWith(t)))

2、asInstanceOf

 def rand2(size:Int,seed:Int):SparseVector={

  val rand=new Random(seed)
val ret_indices=Array.range(0,size)
val ret_values=Array.tabulate[Double](size)(i=>rand.nextDouble()) //从函数创建数组
Vectors.sparse(size, ret_indices, ret_values).asInstanceOf[SparseVector]
}

注意: Vectors.sparse(size, ret_indices, ret_values) 是Vectors下的一个表达稀疏矩阵方式,与 SparseVector是不同的。
所以,需要一步转换的操作。.asInstanceOf[SparseVector]

3、tabulate //从函数创建数组
val ret_values=Array.tabulate[Double](size)(i=>rand.nextDouble())  


原文地址:https://www.cnblogs.com/zhangbojiangfeng/p/7366470.html