如何用 2 个值拆箱矢量

How to unbox vector with 2 values

我正在尝试按照给定的方式进行 wilcoxonMatchedPairTest here

import Data.Vector as V
import Statistics.Test.WilcoxonT

sampleA = [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
sampleB = [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))

但是,我收到以下错误:

rnwilcox.hs:10:50: error:
    • Couldn't match expected type ‘Data.Vector.Unboxed.Base.Vector
                                      (a0, a0)’
                  with actual type ‘[(Double, Double)]’
    • In the second argument of ‘wilcoxonMatchedPairTest’, namely
        ‘(Prelude.zip sampleA sampleB)’
      In the first argument of ‘print’, namely
        ‘(wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))’
      In a stmt of a 'do' block:
        print
          (wilcoxonMatchedPairTest AGreater (Prelude.zip sampleA sampleB))

显然,我需要在这里拆箱矢量。我尝试使用 # 如下:

(# Prelude.zip sampleA sampleB #)

但是不行。问题出在哪里,如何解决?感谢您的帮助。

您需要从 Data.Vector.Unboxed 包中将 2 元组列表转换为带有 fromList :: Unbox a => [a] -> Vector aVector 以创建这样的向量:

import Data.Vector.Unboxed as <b>VU</b>
import Statistics.Test.WilcoxonT

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (<b>VU.fromList</b> (Prelude.zip sampleA sampleB)))

或者如果您有两个 Vector,您可以使用 zip :: (Unbox a, Unbox b) => Vector a -> Vector b -> Vector (a, b) 将两个 Vector 压缩到 Vector 个项目:

import Data.Vector.Unboxed as <b>VU</b>
import Statistics.Test.WilcoxonT

sampleA = VU.fromList [1.0,2.0,3.0,4.0,1.0,2.0,3.0,4]
sampleB = VU.fromList [2.0,4.0,5.0,5.0,3.0,4.0,5.0,6]

main = do
    putStrLn "\nResult of wilcoxonMatchedPairTest: "
    print (wilcoxonMatchedPairTest AGreater (<b>VU.zip</b> sampleA sampleB))

对于给定的样本数据,这给了我们:

Prelude VU Statistics.Test.WilcoxonT> main

Result of wilcoxonMatchedPairTest: 
Test {testSignificance = mkPValue 1.0, testStatistics = 36.0, testDistribution = ()}