Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

A General Analytic Matrix Program for constructing Zero of spark MLlib

Shulou Source: shulou.com Published: 2022-06-03 01:37:19 10月05日 Update

When using spark MLlib, it is sometimes necessary to use some basic matrices (vectors), such as all-zero matrices, all-one matrices, and operations between matrices. Here are some common matrix manipulation methods:

Matrix:

Package utils

Import java.util.Random

/ * *

* dense matrix for encapsulating model parameters

, /

Class DenseMatrix (rowNum: Int, columnNum: Int) extends Serializable {

Var matrix = Array.ofDim [Double] (rowNum, columnNum)

Def rows (): Int = {

RowNum

}

Def columns (): Int = {

ColumnNum

}

Def apply (I: Int): Array [Double] = {

Matrix (I)

}

/ * *

* construct 0 matrix

, /

Def zeros (): DenseMatrix = {

For (I)

Tags: Matrix vector sparse inter parameter foundation common method sometimes model encapsulation operation program Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MySQL Linux Redmi macOS