Logo

Programming-Idioms

Calculate n, the Euclidean norm of data (an array or list of floating point values).
Implementation
Pascal

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Pascal implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
n = norm2( data )
use Math::GSL::Vector qw();
use Math::GSL::BLAS qw(gsl_blas_dnrm2);
my $data = [5.0, 4.0, 3.0, 2.0, 1.0];
my $n = gsl_blas_dnrm2(Math::GSL::Vector->new($data)->raw);
require 'matrix'
data = Vector[5.0, 4.0, 3.0, 2.0, 1.0]
n = data.norm
import numpy as np
np.linalg.norm(adata2[:, 0:3] - adata1[ipc1, 0:3], axis=1)
const n = Math.hypot(...data)
var n = Math.hypot.apply(null, data)
data := #( 5 4 3 2 1 ).
n := data squared sum sqrt.
import numpy as np
n = np.linalg.norm(data)
double n = 0d;
for(double value : data) {
	n += value * value;
}
n = Math.sqrt(n);
func Euclidean(data []float64) float64 {
	n := 0.0
	for _, val := range data {
		n += val * val
	}
	return math.Sqrt(n)
use libm::sqrt;
fn euclidean(data: Vec<f64>) -> f64 {
    let mut n = 0.0;
    for i in data {
        n += i*i;
    }
    return sqrt(n as f64)
}
let n = euclidean(data);