{"id":5460,"date":"2017-10-05T12:17:33","date_gmt":"2017-10-05T12:17:33","guid":{"rendered":"http:\/\/www.garysieling.com\/blog\/?p=5460"},"modified":"2017-10-05T12:17:33","modified_gmt":"2017-10-05T12:17:33","slug":"nd4j-normalize-vector","status":"publish","type":"post","link":"https:\/\/www.garysieling.com\/blog\/nd4j-normalize-vector\/","title":{"rendered":"Nd4j &#8211; normalize vector"},"content":{"rendered":"<p>Here is one approach-<\/p>\n<pre lang=\"scala\">\ndef normalize(vectors: List[(String, INDArray)]) = {\n    vectors.map(\n      (value: (String, INDArray)) => {\n        val vec: INDArray = value._2\n        val vec2: INDArray = vec.mul(vec)\n        val total = vec2.sumNumber()\n\n        value._2.div(sqrt(total.doubleValue()))\n      }\n    )\n  }\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Normalizing a list of nd4j vectors<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[257,300,379,480],"aioseo_notices":[],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5460"}],"collection":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/comments?post=5460"}],"version-history":[{"count":0,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/posts\/5460\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/media?parent=5460"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/categories?post=5460"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.garysieling.com\/blog\/wp-json\/wp\/v2\/tags?post=5460"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}