Multidimensional Array Comprehension in Julia

后端 未结 7 1407
既然无缘
既然无缘 2021-01-11 12:50

I\'m mucking about with Julia and can\'t seem to get multidimensional array comprehensions to work. I\'m using a nightly build of 0.20-pre for OSX; this could conceivably be

7条回答
  •  醉话见心
    2021-01-11 12:57

    I found a way to produce numerical multidimensional arrays via vcat and the splat operator:

    R = [ [x y] for x in 1:3, y in 4:6 ] # make the list of rows
    A = vcat(R...) # make n-dim. array from the row list
    

    Then R will be a 3x3 Array{Array{Int64,2},2} while A is a 9x2 Array{Int64,2}, as you want.

    For the second case (a set of values and a Boolean code for each), one can do something like

    R = [[x y > 5] for x in 1:3, y in 4:6] # condition is y > 5
    A = vcat(R...)
    

    where A will be a 9x2 Array{Int64,2}, where true/false is denote by 1/0.

    I have tested those in Julia 0.4.7.

提交回复
热议问题