scalaapache-sparkscala-breeze

How to replace elements of a breeze matrix in Scala based on some condition?


I am working with 2 dimensional Breeze matrices in Scala. At some point I have to do element-wise division of two matrices. Some elements in the denominator matrix can be zero, resulting into NaNs in the result.

I can loop through the matrix dimensions and replace the 0.0s with something >0.

But is there a simpler or Scala idiomatic solution for this?


Solution

  • Step-by-step: