<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def perpendicular_vector(vec):
 """Return a vector perpendicular to ``vec``. Parameters vec : `array-like` Vector(s) of arbitrary length. The axis along the vector components must come last. Returns ------- perp_vec : `numpy.ndarray` Array of same shape as ``vec`` such that ``dot(vec, perp_vec) == 0`` (along the last axis if there are multiple vectors). Examples -------- Works in 2d: array([-1., 0.]) True And in 3d: array([-1., 0., 0.]) array([ 1., 0., 0.]) True The function is vectorized, i.e., it can be called with multiple vectors at once (additional axes being added to the left):
 array([[-1., 0., 0.], [ 1., 0., 0.]]) array([[[-1., 0., 0.], [-1., 0., 0.], [-1., 0., 0.]], <BLANKLINE> [[-1., 0., 0.], [-1., 0., 0.], [-1., 0., 0.]]]) """

    squeeze_out = (np.ndim(vec) == 1)
    vec = np.array(vec, dtype=float, copy=False, ndmin=2)

    if np.any(np.all(vec == 0, axis=-1)):
        raise ValueError('zero vector')

    result = np.zeros(vec.shape)
    cond = np.any(vec[..., :2] != 0, axis=-1)
    result[cond, 0] = -vec[cond, 1]
    result[cond, 1] = vec[cond, 0]
    result[~cond, 0] = 1
    result /= np.linalg.norm(result, axis=-1, keepdims=True)

    if squeeze_out:
        result = result.squeeze()

    return result