(vector_in, decimals=18)
Generates a unit vector from the input.

    :param vector_in: vector to be normalized
    :type vector_in: list, tuple
    :param decimals: number of significands
    :type decimals: int
    :return: the normalized vector (i.e. the unit vector)
    :rtype: list
Generates a unit vector from the input.
Generates a unit vector from the input .
def vector_normalize(vector_in, decimals=18):
    """ Generates a unit vector from the input.

    :param vector_in: vector to be normalized
    :type vector_in: list, tuple
    :param decimals: number of significands
    :type decimals: int
    :return: the normalized vector (i.e. the unit vector)
    :rtype: list
    """
    try:
        if vector_in is None or len(vector_in) == 0:
            raise ValueError("Input vector cannot be empty")
    except TypeError as e:
        print("An error occurred: {}".format(e.args[-1]))
        raise TypeError("Input must be a list or tuple")
    except Exception:
        raise

    # Calculate magnitude of the vector
    magnitude = vector_magnitude(vector_in)

    # Normalize the vector
    if magnitude > 0:
        vector_out = []
        for vin in vector_in:
            vector_out.append(vin / magnitude)

        # Return the normalized vector and consider the number of significands
        return [float(("{:." + str(decimals) + "f}").format(vout)) for vout in vector_out]
    else:
        raise ValueError("The magnitude of the vector is zero")
def vector_normalize ( vector_in , decimals = 18 ) : try : if vector_in is None or len ( vector_in ) == 0 : raise ValueError ( "Input vector cannot be empty" ) except TypeError as e : print ( "An error occurred: {}" . format ( e . args [ - 1 ] ) ) raise TypeError ( "Input must be a list or tuple" ) except Exception : raise # Calculate magnitude of the vector magnitude = vector_magnitude ( vector_in ) # Normalize the vector if magnitude > 0 : vector_out = [ ] for vin in vector_in : vector_out . append ( vin / magnitude ) # Return the normalized vector and consider the number of significands return [ float ( ( "{:." + str ( decimals ) + "f}" ) . format ( vout ) ) for vout in vector_out ] else : raise ValueError ( "The magnitude of the vector is zero" )