官术网_书友最值得收藏!

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))

主站蜘蛛池模板: 张北县| 屏东市| 宁化县| 玉溪市| 曲松县| 靖州| 车险| 元江| 个旧市| 临夏市| 那曲县| 久治县| 马山县| 望江县| 新竹县| 磐安县| 文化| 会东县| 灵寿县| 安多县| 开鲁县| 潞西市| 广德县| 巨鹿县| 巩义市| 中西区| 罗山县| 敦煌市| 丹江口市| 北辰区| 商南县| 东乌珠穆沁旗| 宣武区| 台中市| 永和县| 启东市| 汕头市| 龙里县| 桃园县| 盐津县| 昂仁县|