Spark机器学习库-矩阵or向量的求和函数

Spark机器学习库-矩阵or向量的求和函数_第1张图片

package com.sparktest.demo

import breeze.linalg.{Axis, DenseMatrix, DenseVector, accumulate, sum, trace}

/**
  * Created by HeartisTiger on 2019/7/8
  */
object Demo05 {
  def main(args: Array[String]): Unit = {
    var m1 = new DenseMatrix[Int](3,3,Array(1,2,3,4,5,6,7,8,9))
    val v1 = DenseVector(1,2,3,4,5,6)
    //求和
    println(sum(m1))

    //每一列求和
    println(sum(m1, Axis._0))

    //每一行求和
    println(sum(m1, Axis._1))

    //对角线元素和
    println(trace(m1))

    //向量累积和
    println(accumulate(v1))


  }
}

你可能感兴趣的:(大数据,机器学习)