Nd4j – normalize vector

Here is one approach-

def normalize(vectors: List[(String, INDArray)]) = {
    vectors.map(
      (value: (String, INDArray)) => {
        val vec: INDArray = value._2
        val vec2: INDArray = vec.mul(vec)
        val total = vec2.sumNumber()
 
        value._2.div(sqrt(total.doubleValue()))
      }
    )
  }

Interested in Scala? I send out weekly, personalized emails with articles and conference talks. Click here to see an example and subscribe.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *