def unit_conversion(array, unit_prefix, current_prefix=""):
    """
    Converts an array or value to of a certain 
    unit scale to another unit scale.

    Accepted units are:
    E - exa - 1e18
    P - peta - 1e15
    T - tera - 1e12
    G - giga - 1e9
    M - mega - 1e6
    k - kilo - 1e3
    m - milli - 1e-3
    u - micro - 1e-6
    n - nano - 1e-9
    p - pico - 1e-12
    f - femto - 1e-15
    a - atto - 1e-18

    Parameters
    ----------
    array : ndarray
        Array to be converted
    unit_prefix : string
        desired unit (metric) prefix (e.g. nm would be n, ms would be m)
    current_prefix : optional, string
        current prefix of units of data (assumed to be in SI units
        by default (e.g. m or s)

    Returns
    -------
    converted_array : ndarray
        Array multiplied such as to be in the units specified
    """
    UnitDict = {
        'E': 1e18,
        'P': 1e15,
        'T': 1e12,
        'G': 1e9,
        'M': 1e6,
        'k': 1e3,
        '': 1,
        'm': 1e-3,
        'u': 1e-6,
        'n': 1e-9,
        'p': 1e-12,
        'f': 1e-15,
        'a': 1e-18,
    }
    try:
        Desired_units = UnitDict[unit_prefix]
    except KeyError:
        raise ValueError("You entered {} for the unit_prefix, this is not a valid prefix".format(unit_prefix))
    try:
        Current_units = UnitDict[current_prefix]
    except KeyError:
        raise ValueError("You entered {} for the current_prefix, this is not a valid prefix".format(current_prefix))
    conversion_multiplication = Current_units/Desired_units
    converted_array = array*conversion_multiplication
    return converted_array
def unit_conversion ( array , unit_prefix , current_prefix = "" ) : UnitDict = { 'E' : 1e18 , 'P' : 1e15 , 'T' : 1e12 , 'G' : 1e9 , 'M' : 1e6 , 'k' : 1e3 , '' : 1 , 'm' : 1e-3 , 'u' : 1e-6 , 'n' : 1e-9 , 'p' : 1e-12 , 'f' : 1e-15 , 'a' : 1e-18 , } try : Desired_units = UnitDict [ unit_prefix ] except KeyError : raise ValueError ( "You entered {} for the unit_prefix, this is not a valid prefix" . format ( unit_prefix ) ) try : Current_units = UnitDict [ current_prefix ] except KeyError : raise ValueError ( "You entered {} for the current_prefix, this is not a valid prefix" . format ( current_prefix ) ) conversion_multiplication = Current_units / Desired_units converted_array = array * conversion_multiplication return converted_array
Converts an array or value to of a certain 
    unit scale to another unit scale.

    Accepted units are:
    E - exa - 1e18
    P - peta - 1e15
    T - tera - 1e12
    G - giga - 1e9
    M - mega - 1e6
    k - kilo - 1e3
    m - milli - 1e-3
    u - micro - 1e-6
    n - nano - 1e-9
    p - pico - 1e-12
    f - femto - 1e-15
    a - atto - 1e-18

    Parameters
    ----------
    array : ndarray
        Array to be converted
    unit_prefix : string
        desired unit (metric) prefix (e.g. nm would be n, ms would be m)
    current_prefix : optional, string
        current prefix of units of data (assumed to be in SI units
        by default (e.g. m or s)

    Returns
    -------
    converted_array : ndarray
        Array multiplied such as to be in the units specified