I have two numpy arrays:
lst = np.array([8, 1, 6, 9, 2])
arr = np.array([[[ 6, 455],
[ 8, 106],
[ 1, 953],
[ 2, 725],
[ 9, 427]],
[[ 2, 427],
[ 8, 953],
[ 1, 106],
[ 9, 455],
[ 6, 725]]])
Note that arr[0,:,0] and arr[1,:,0] are both permutations of lst.
I want to sort arr such that both arr[0,:,0] and arr[1,:,0] are in the same order as lst (and the rows are correctly sorted). In other words, I want the following outcome:
ans = np.array([[[ 8, 106],
[ 1, 953],
[ 6, 455],
[ 9, 427],
[ 2, 725]],
[[ 8, 953],
[ 1, 106],
[ 6, 725],
[ 9, 455],
[ 2, 427]]])
I can get my desired outcome using list comprehension, but I'm looking for a more efficient solution. Can anyone help me? Thank you.