def actions2trajectory(position, actions):
    """
    helper function to map a set of actions to a trajectory.

    action convention:
    1 - upper left, 2 - up,   3 - upper right
    4 - left,       0 - stop, 5 - right
    6 - lower left, 7 - down, 8 -lower right

    Inputs:
    - position: numpy array representing (x, y) position
    - actions: list of integers (see convention) describing movement actions

    Returns:
    - trajectory: list of (x, y) positions created by taking actions, where the
                  first element is the input position
    """

    trajectory = []
    x, y = position
    trajectory.append((x, y))
    for a in actions:
        x, y = trajectory[-1]
        if a == 0:
            trajectory.append((x, y))
        elif a == 1:
            trajectory.append((x-1, y+1))
        elif a == 2:
            trajectory.append((x, y+1))
        elif a == 3:
            trajectory.append((x+1, y+1))
        elif a == 4:
            trajectory.append((x-1, y))
        elif a == 5:
            trajectory.append((x+1, y))
        elif a == 6:
            trajectory.append((x-1, y-1))
        elif a == 7:
            trajectory.append((x, y-1))
        elif a == 8:
            trajectory.append((x+1, y-1))

    return trajectory