- 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))
推薦閱讀
- PIC單片機C語言非常入門與視頻演練
- PHP開發(fā)手冊
- 計算機網(wǎng)絡(luò)技術(shù)實訓(xùn)
- Photoshop CS3特效處理融會貫通
- Docker Quick Start Guide
- PyTorch Deep Learning Hands-On
- 運動控制器與交流伺服系統(tǒng)的調(diào)試和應(yīng)用
- 計算機網(wǎng)絡(luò)原理與技術(shù)
- 面向?qū)ο蟪绦蛟O(shè)計綜合實踐
- 計算機與信息技術(shù)基礎(chǔ)上機指導(dǎo)
- 走近大數(shù)據(jù)
- Linux Shell編程從初學(xué)到精通
- 電腦上網(wǎng)入門
- Cortex-M3嵌入式處理器原理與應(yīng)用
- ORACLE數(shù)據(jù)庫技術(shù)實用詳解