def pyargsort(seq, cmp=None, key=lambda x: x):
    """Like numpy's argsort, but using the builtin Python sorting
    function.  Takes an optional cmp."""
    return sorted(list(range(len(seq))), key=lambda x: key(seq.__getitem__(
        x)), cmp=None)
