假设我有两个向量:
let x = V.fromList ["foo", "bar", "baz"]
let y = V.fromList [1,3,2]
我想定义一个向量 y'
,它是 y
的排序版本,但我还想定义一个重新排序的 x'
它是根据 y
的排序顺序排序的(x'
应该看起来像 ["foo", "baz", "bar"]
).
最好的功能是什么?理想情况下,我想避免从头开始编写排序函数。
最佳答案
我想你在找backpermute
backpermute :: Vector a -> Vector Int -> Vector a
O(n) Yield the vector obtained by replacing each element
i
of the index vector byxs!i
. This is equivalent tomap (xs!)
is but is often much more efficient.
关于sorting - 如何根据 haskell 中另一个向量的排序顺序对向量值进行重新排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37682168/