- 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))
推薦閱讀
- Getting Started with Containerization
- 空間傳感器網(wǎng)絡復雜區(qū)域智能監(jiān)測技術(shù)
- Python Algorithmic Trading Cookbook
- Photoshop CS3特效處理融會貫通
- RPA:流程自動化引領(lǐng)數(shù)字勞動力革命
- 統(tǒng)計策略搜索強化學習方法及應用
- Android游戲開發(fā)案例與關(guān)鍵技術(shù)
- INSTANT Drools Starter
- Deep Reinforcement Learning Hands-On
- 貫通Java Web開發(fā)三劍客
- 邊緣智能:關(guān)鍵技術(shù)與落地實踐
- 統(tǒng)計挖掘與機器學習:大數(shù)據(jù)預測建模和分析技術(shù)(原書第3版)
- 計算機硬件技術(shù)基礎(chǔ)學習指導與練習
- 工業(yè)機器人應用系統(tǒng)三維建模
- iLike就業(yè)SQL多功能教材