Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Fortran

Idiom #201 Euclidean norm

Calculate n, the Euclidean norm of data, where data is a list of floating point values.

n = norm2( data )

data may be a multidimensional array (e.g. data(:,:)). n is the Frobenius norm if data is a 2-dimensional array (matrix).
func Euclidean(data []float64) float64 {
	n := 0.0
	for _, val := range data {
		n += val * val
	}
	return math.Sqrt(n)

New implementation...
< >
Bart