Skip to content

compute l2norm

kgryte edited this page May 12, 2015 · 1 revision

Computes the L2 norm (Euclidean norm) of an array.

var data = [ 2, 4, 2, 7, 3 ];

var norm = compute.l2norm( data );
// returns ~9.06

For object arrays, provide an accessor function for accessing numeric values.

var data = [
	{'x':2},
	{'x':4},
	{'x':2},
	{'x':7},
	{'x':3}
];

function getValue( d, i ) {
	return d.x;
}

var norm = compute.l2norm( data, getValue );
// returns ~9.06

If provided an empty array, the method returns null.

Clone this wiki locally