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

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.

No credit card required