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

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

主站蜘蛛池模板: 紫金县| 盘锦市| 民丰县| 黎平县| 祁阳县| 湛江市| 兴业县| 玉龙| 长寿区| 福建省| 兰坪| 修水县| 穆棱市| 鄯善县| 龙海市| 江陵县| 海晏县| 鹤峰县| 论坛| 贺州市| 筠连县| 景德镇市| 商河县| 荆州市| 社旗县| 堆龙德庆县| 桃江县| 义马市| 贵州省| 措美县| 永仁县| 乌苏市| 临城县| 黄大仙区| 阿尔山市| 灌云县| 凤阳县| 宾川县| 剑川县| 上蔡县| 静安区|