def sort_xy(x, y):
''' Sorts a pair of x and y iterables, returning arrays in order of
ascending x.
Args:
x (`iterable`): a list, numpy ndarray, or other iterable to sort by.
y (`iterable`): a list, numpy ndarray, or other iterable that is y=f(x).
Returns:
tuple containing:
`iterable`: an iterable containing the sorted x elements.
`iterable`: an iterable containing the sorted y elements.
'''
# zip x and y, sort by the 0th element (x) of each tuple in zip()
_ = sorted(zip(x, y), key=itemgetter(0))
sorted_x, sorted_y = zip(*_)
return sorted_x, sorted_y
评论列表
文章目录