如何解开具有2个值的向量

时间:2019-09-12 18:29:25

标签: haskell statistics box haskell-vector

我正在尝试按照给出的here进行wilcoxonMatchedPairTest:

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 #)

但是它不起作用。问题在哪里,如何解决?感谢您的帮助。

1 个答案:

答案 0 :(得分:3)

您需要通过 String dateFormatter ="20190911T14:37:08.7770400"; SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMDD'T'HH:mm:ss.SSSZZZZ"); //tried the below commnet also //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-d'T'HH:mm:ss.SSSZZZZ"); System.out.println(sdf.parse(dateFormatter)); Error: "Exception in thread "main" java.text.ParseException: Unparseable date: "20190911T14:37:08.7770400" at java.text.DateFormat.parse(DateFormat.java:366) at com.sudha.test.sample_boot_example.TestString.main(TestString.java:20) 包中的fromList :: Unbox a => [a] -> Vector a将2元组的列表转换为Vector,以创建这样的向量:

Data.Vector.Unboxed

或者如果您有两个import Data.Vector.Unboxed as VU import Statistics.Test.WilcoxonT main = do putStrLn "\nResult of wilcoxonMatchedPairTest: " print (wilcoxonMatchedPairTest AGreater (VU.fromList (Prelude.zip sampleA sampleB))),则可以使用zip :: (Unbox a, Unbox b) => Vector a -> Vector b -> Vector (a, b)将两个Vector压缩到Vector个项目中:

Vector

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

import Data.Vector.Unboxed as VU
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 (VU.zip sampleA sampleB))