我有兩個惹巴陣列a1
和a2
和我想消除在a2
所有元素爲其在a1
相應索引是高於某個閾值。例如:如何通過謂詞上索引來篩選惹巴
import qualified Data.Array.Repa as R -- for Repa
import Data.Array.Repa (Z (..), (:.)(..))
a1 = R.fromFunction (Z :. 4) $ \(Z :. x) -> [8, 15, 9, 14] ! x
a2 = R.fromFunction (Z :. 4) $ \(Z :. x) -> [0, 1, 2, 3] ! x
threshold = 10
desired = R.fromFunction (Z :. 2) $ \(Z :. x) -> [0, 2] ! x
-- 15 and 14 are above the threshold, 10
的一種方式做,這是與selectP
,但我想避免使用這個,因爲它計算陣列,我想我的陣列,留在延遲形式,如果可能的。
另一種方法是與repa-array
,但stack solver
似乎不知道如何導入此庫與解析器nightly-2017-04-10
。
如果是這樣的只有你需要的東西,將它作爲一組對來建模會更好。這裏的順序沒有意義,只有特定的元素配對在一起。 – Lazersmoke