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

Vector operations

Vectors can be added together, subtracted, and multiplied by scalars. Other operations on vectors include finding the mean, normalization, comparison, and geometrical representation.

  • The Add operation: This code shows an element-wise add operation on vector objects:
        // vector's         val v1 = DenseVector(3, 7, 8.1, 4, 5)         val v2 = DenseVector(1, 9, 3, 2.3, 8)         // elementwise add operation         def add(): Unit = {           println(v1 + v2)         } 

This last code gives us the result as follows: DenseVector(4.0, 16.0, 11.1, 6.3, 13.0)

  • Multiply and Dot operation: It is an algebraic operation, which takes two sequences of an equal length of numbers, and returns a single number; algebraically, it is the sum of the products of the corresponding ...

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