Here you can find the source of vectorLength(double[] vector)
Parameter | Description |
---|---|
vector | the vector to return the vector length for |
public static double vectorLength(double[] vector)
//package com.java2s; /*/*from w w w . j a v a2 s .com*/ * * Copyright 2016 Skymind, Inc. * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. */ public class Main { /** * Returns the vector length (sqrt(sum(x_i)) * * @param vector the vector to return the vector length for * @return the vector length of the passed in array */ public static double vectorLength(double[] vector) { double ret = 0; if (vector == null) return ret; else { for (double aVector : vector) { ret += Math.pow(aVector, 2); } } return ret; } }