Skip to content

Instantly share code, notes, and snippets.

@Nomad-Go
Created January 14, 2019 21:39
Show Gist options
  • Select an option

  • Save Nomad-Go/9a782b72c91c245070b5aef2a3d2c86b to your computer and use it in GitHub Desktop.

Select an option

Save Nomad-Go/9a782b72c91c245070b5aef2a3d2c86b to your computer and use it in GitHub Desktop.
Calculate the L2 Norm of a `[Double]` value in Swift
/** 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