Java Utililty Methods Array Normalize

List of utility methods to do Array Normalize

Description

The list of methods to do Array Normalize are organized into topic(s).

Method

double[]normalize(final double[] tab)
normalize
if (tab == null) {
    throw new NullPointerException("Array cannot be null");
if (tab.length == 0) {
    throw new IllegalArgumentException("Array has zero length");
double max = Math.abs(tab[maxAbs(tab)]);
for (int i = 0; i < tab.length; i++) {
...
booleannormalize(final double[] vec)
Normalize a vector, i.e.
assert vec != null;
final double sum = sum(vec);
if (sum != 0.) {
    for (int i = 0; i < vec.length; i++) {
        vec[i] /= sum;
    assert sum(vec) == 1.;
    return true;
...
double[]normalize(final double[] vector, final double[] minima, final double[] maxima)
normalize
if (minima.length != maxima.length) {
    throw new RuntimeException("Vector minima and maxima have different lengths.");
if (vector.length != maxima.length) {
    throw new RuntimeException("Vector vector and maxima have different lengths.");
final double[] result = new double[vector.length];
for (int i = 0; i < vector.length; i++) {
...
floatnormalize(float p[])
normalize
float w = (float) Math.sqrt(p[0] * p[0] + p[1] * p[1] + p[2] * p[2]);
if (w > 0.000001f) {
    p[0] /= w;
    p[1] /= w;
    p[2] /= w;
return w;
voidnormalize(float[] data)
Normalize the given data.
float sum = 0;
for (float val : data) {
    sum += val;
if (sum != 0.0f) {
    for (int i = 0; i < data.length; i++) {
        data[i] = data[i] / sum;
float[]normalize(float[] in)
Make the array into a unit array
double sumofsquares = 0;
for (int k = 0; k < in.length; ++k)
    sumofsquares += in[k] * in[k];
final float norm = (float) Math.sqrt(sumofsquares);
for (int k = 0; k < in.length; ++k)
    in[k] /= norm;
return in;
float[]normalize(float[] in)
normalize
float[] out = new float[in.length];
float sum = 0;
for (int i = 0; i < in.length; i++) {
    sum += in[i] * in[i];
sum = (float) Math.sqrt(sum);
for (int i = 0; i < in.length; i++) {
    out[i] = in[i] / sum;
...
voidnormalize(float[] input)
Normalizes the given input in place to make it unit length.
double normSq = 0;
for (int i = 0; i < input.length; ++i) {
    normSq += input[i] * input[i];
float norm = (float) Math.sqrt(normSq);
for (int i = 0; i < input.length; ++i) {
    input[i] = input[i] / norm;
float[]normalize(float[] v)
Normalize vector
float r;
r = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
if (r == 0.0)
    return v;
r = 1.0f / r;
v[0] *= r;
v[1] *= r;
v[2] *= r;
...
voidnormalize(float[] vec)
normalize
float a = 1.f / length(vec);
multVector(vec, a);