[英]How can I sort each row of the 2d numpy-array by another 2d index-array?
例如,我有:
arr = np.array[[10 30 20],
[30 20 10]]
indices = np.array[[2 1 0],
[2 1 0]]
我想要:
[[20 30 10],
[10 20 30]]
非常感谢!!
import numpy as np
arr = np.array([[10, 30, 20],
[30, 20, 10]])
indices = np.array([[2, 1, 0],
[2, 1, 0]])
res = np.take_along_axis(arr, indices, axis=1)
print(res)
输出
[[20 30 10]
[10 20 30]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.