<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(n):
 """ Get a random vector perpendicular to the given vector """

    dim = len(n)
    if dim == 2:
        return n[::-1]
    # More complex in 3d
    for ix in range(dim):
        _ = N.zeros(dim)
        # Try to keep axes near the global projection
        # by finding vectors perpendicular to higher-
        # index axes first. This may or may not be worth
        # doing.
        _[dim-ix-1] = 1
        v1 = N.cross(n,_)
        if N.linalg.norm(v1) != 0:
            return v1
    raise ValueError("Cannot find perpendicular vector")