Search code examples
scalascala-breeze

Scala: Projecting negative elements in DenseMatrix to 0


In python, if I want to set negative entries from a matrix A, I could do:

    A = np.max(A, 0)

Is there a similar method in Scala? I have a matrix with Breeze DenseMatrix type.


Solution

  • breeze.linalg.max(A, 0.0)

    (Using 0.0 instead of 0 is important, because Breeze doesn't automatically promote scalar types.)