Created
January 14, 2019 21:39
-
-
Save Nomad-Go/9a782b72c91c245070b5aef2a3d2c86b to your computer and use it in GitHub Desktop.
Calculate the L2 Norm of a `[Double]` value in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** Calculate the L2 Norm **/ | |
| func l2Normalization(vector: [Double]) -> Double { | |
| var sum: Double = 0 | |
| for i in vector { | |
| sum += pow(i, 2) | |
| } | |
| return sqrt(sum) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment