Julia

时间:2015-10-22 08:27:47

标签: julia

您好,

更多地了解朱莉娅(0.4.0),我面临一个有趣的情况,可能是一个简单的解决方案让我感到厌烦。

我有一个与此类似的数组:

17200x11 Array{Any,2}:
 1  -16.449    -1.091    -3.6087  -12.6724   -1.5945  -14.7705   -7.2174  -25.2609   -3.7766  -14.3509
 1  -16.6168   -5.2032    1.091    -3.8605    1.1749  -11.6653   -6.1264  -16.3651   -2.0142  -14.0991
 1  -16.8686   -7.3853    3.8605    6.2103   -0.9232   -6.546    -8.1406  -10.0708   -2.2659  -16.3651
 1  -16.5329  -10.4904   -1.7624    8.1406  -10.2386    1.3428  -16.0294   -6.4621   -4.6158  -19.5541
 1  -13.8474  -13.5117  -13.6795    1.9302  -18.5471    3.6087  -22.995    -4.2801   -8.2245  -17.9596
 1   -9.1476  -13.7634  -20.6451   -1.7624  -18.2953    1.091   -24.0021   -2.7695  -10.4904   -8.3923
 1   -4.6997   -8.9798  -14.267     1.6785  -10.7422    1.1749  -19.3024   -2.2659  -11.0779   -2.6016

我已经构建了一个像这样的函数:

function aligner(mat,sc=schord)
  ls=@parallel vcat for i=1:Int64(size(mat,1)/sc)
hcat(mat[((i-1)*sc+1),1],reshape(mat[((i-1)*sc+1):(i*sc),2:end],length(mat[((i-1)*sc+1):(i*sc),2:end]))') # reshape to convert array to vector and ' to transpose
  end
  return ls
end

运行此行

tmpU=aligner(tmpR,100)

我收到了这个错误:

ERROR: DimensionMismatch("mismatch in dimension 1 (expected 1 got 100)")
 in cat_t at abstractarray.jl:824
 in hcat at abstractarray.jl:849
 [inlined code] from none:3
 in anonymous at no file:1500
 in anonymous at multi.jl:684
 in run_work_thunk at multi.jl:645
 in remotecall_fetch at multi.jl:718
 in remotecall_fetch at multi.jl:734
 in anonymous at multi.jl:1485
 in yieldto at /Applications/Julia-0.4.0.app/Contents/Resources/julia/lib/julia/sys.dylib
 in wait at /Applications/Julia-0.4.0.app/Contents/Resources/julia/lib/julia/sys.dylib (repeats 3 times)
 in preduce at multi.jl:1489
 [inlined code] from multi.jl:1498
 in anonymous at expr.jl:1543
 in aligner at none:2

奇怪的是,如果我只使用函数的核心(当然,mat = myArray和sc = 100),它的效果非常好。

ls=@parallel vcat for i=1:Int64(size(mat,1)/sc)
           hcat(mat[((i-1)*sc+1),1],reshape(mat[((i-1)*sc+1):(i*sc),2:end],length(mat[((i-1)*sc+1):(i*sc),2:end]))') # reshape to convert array to vector and ' to transpose
end
172x1001 Array{Any,2}:
 1  -16.449   -16.6168  -16.8686  -16.5329  -13.8474   -9.1476   -4.6997  …   10.3226    3.273    -0.2518    4.364     7.2174    1.3428   -6.2103
 1  -21.6522  -14.6866  -15.0223  -19.9738  -21.7361  -22.5754  -23.3307      12.1689   12.1689    8.0566    3.6926    3.0212    3.9444    1.3428
 1   -6.6299   -4.6997    3.6926    7.5531    7.3013    4.1962    5.3711     -15.5258  -12.2528   -7.5531   -7.1335  -12.3367  -17.4561  -17.2882
 1    9.903     5.9586    3.3569    4.1962    4.8676    4.6997    8.3923       0.9232   -0.5035   -5.9586   -9.9869   -9.6512   -1.7624    4.4479
 1   19.1345   14.183    10.1547   10.4904    8.2245    2.4338   -3.6926      -4.8676   -6.7978   -8.8959  -11.5814  -15.0223  -11.0779   -3.1891
 1   -3.1052   -0.7553    6.3782    6.2943    0.9232    0.8392    4.0283  …   -8.0566   -8.5602   -9.5673  -10.6583   -8.0566   -2.2659    1.2589

感谢您理解/解决问题的任何帮助。

亲切的问候,RN

1 个答案:

答案 0 :(得分:0)

嗯,似乎解决方案非常简单:

function aligner(mat::Array,sc::Int=schord)
  ls::Array=@parallel vcat for i=1:Int64(size(mat,1)/sc)
    hcat(mat[((i-1)*sc+1),1],reshape(mat[((i-1)*sc+1):(i*sc),2:end],length(mat[((i-1)*sc+1):(i*sc),2:end]))') # reshape to convert array to vector and ' to transpose
  end
  return ls
end

<!/ P>