O'Reilly logo

Machine Learning with Spark - Second Edition by Nick Pentreath, Manpreet Singh Ghotra, Rajdeep Dua

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required