<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def internal2external_grad(xi, bounds):
 """ Calculate the internal to external gradiant Calculates the partial of external over internal """


    ge = np.empty_like(xi)

    for i, (v, bound) in enumerate(zip(xi, bounds)):

        a = bound[0]  # minimum
        b = bound[1]  # maximum

        if a == None and b == None:  # No constraints
            ge[i] = 1.0

        elif b == None:  # only min
            ge[i] = v / np.sqrt(v ** 2 + 1)

        elif a == None:  # only max
            ge[i] = -v / np.sqrt(v ** 2 + 1)

        else:  # both min and max
            ge[i] = (b - a) * np.cos(v) / 2.

    return ge