我正在尝试重新排列一些数组,但它似乎并不总是正常工作:
# Works fine
arr = np.array([2,3,1])
idx1 = np.array([1,0,2])
arr[idx1]
>> array([3, 2, 1])
# Doesn't work
arr = np.array([2,3,1])
idx2 = np.array([2,0,1])
arr[idx2]
>> array([1, 2, 3]) # Should have been [3,1,2]
我做错什么了吗?你知道吗
Tags:
索引使用索引数组重建数组。索引数组包含原始数组中元素的位置(索引)列表。你知道吗
就你而言:
索引
[2, 0, 1]
表示[third element, first element, second element]
用
arr[idx2]
你得到[1, 2, 3]
。是的。你知道吗示例:带有第二和第三个元素的索引
相关问题 更多 >
编程相关推荐