Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #201 Euclidean norm

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

n = norm2( data )
var n = Math.hypot.apply(null, data)
const n = Math.hypot(...data)
uses math;
var
  data: array of double;
...
  n := norm(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);
import numpy as np
np.linalg.norm(data)
require 'matrix'
data = Vector[5.0, 4.0, 3.0, 2.0, 1.0]
n = data.norm
data := #( 5 4 3 2 1 ).
n := data squared sum sqrt.

New implementation...
< >
Bart