- Machine Learning with Spark(Second Edition)
- Rajdeep Dua Manpreet Singh Ghotra Nick Pentreath
- 147字
- 2021-07-09 21:07:48
Vectors in Breeze
Breeze uses two basic vector types-breeze.linalg.DenseVector and breeze.linalg.SparseVector-to represent the two vector types shown earlier.
DenseVector is a wrapper around an array which supports numeric operations. Let's first look at the dense vector computation; we will create a dense vector object using Breeze, and then update index three to a new value.
import breeze.linalg.DenseVector
val v = DenseVector(2f, 0f, 3f, 2f, -1f)
v.update(3, 6f)
println(v)
This gives us the following result: DenseVector (2.0, 0.0, 3.0, 6.0, -1.0)
SparseVectoris a vector with most of its values at zero, and supports numeric operations. Let's look at the sparse vector computation; we will a create sparse vector object using Breeze, and then update the values by one.
import breeze.linalg.SparseVectorval sv:SparseVector[Double] =
SparseVector(5)()
sv(0) = 1
sv(2) = 3
sv(4) = 5
val m:SparseVector[Double] = sv.mapActivePairs((i,x) => x+1)
println(m)
This gives us the following result: SparseVector((0,2.0), (2,4.0), (4,6.0))
推薦閱讀
- Microsoft Power BI Quick Start Guide
- 計(jì)算機(jī)原理
- Visual FoxPro 6.0數(shù)據(jù)庫(kù)與程序設(shè)計(jì)
- PIC單片機(jī)C語(yǔ)言非常入門(mén)與視頻演練
- Matplotlib 3.0 Cookbook
- 電腦上網(wǎng)直通車
- Windows程序設(shè)計(jì)與架構(gòu)
- Photoshop CS3圖像處理融會(huì)貫通
- JavaScript典型應(yīng)用與最佳實(shí)踐
- 精通數(shù)據(jù)科學(xué)算法
- 大數(shù)據(jù)技術(shù)基礎(chǔ):基于Hadoop與Spark
- 嵌入式GUI開(kāi)發(fā)設(shè)計(jì)
- Linux系統(tǒng)下C程序開(kāi)發(fā)詳解
- 網(wǎng)絡(luò)服務(wù)器搭建與管理
- 工業(yè)機(jī)器人技術(shù)