- 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))
推薦閱讀
- Ansible Configuration Management
- 輕松學(xué)C語言
- ABB工業(yè)機器人編程全集
- Photoshop CS4經(jīng)典380例
- Apache Hive Essentials
- 計算機圖形圖像處理:Photoshop CS3
- 深度學(xué)習(xí)中的圖像分類與對抗技術(shù)
- Ceph:Designing and Implementing Scalable Storage Systems
- 激光選區(qū)熔化3D打印技術(shù)
- 多媒體制作與應(yīng)用
- 電腦上網(wǎng)輕松入門
- 從零開始學(xué)SQL Server
- Artificial Intelligence By Example
- 三菱FX/Q系列PLC工程實例詳解
- 3ds Max造型表現(xiàn)藝術(shù)