Actually, `[]` is `Array{None, 1}`, which leads to some confusing behavior
julia> []
0-element Array{None,1}
julia> [].'
1x0 Array{None,2}
julia> [[] [1 2]]
ERROR: mismatch in dimension 1
in cat_t at abstractarray.jl:680
in hcat at abstractarray.jl:719
julia> [[].' [1 2]]
1x2 Array{Int64,2}:
1 2
Is this on purpose or a bug? (Julia Version 0.3.0-prerelease+1400, Commit
6f3a4b6* (2014-02-05 19:14 UTC))
Best,
Alex.
On Saturday, 1 March 2014 11:15:04 UTC+1, Ivar Nesje wrote:
>
> One problem you have is the decision that was made to make `[]` create the
> unusable `Array{Nothing, 0}`. To create an array that you can actually fill
> with values, you need to specify the type (eg. `Float64[]`)
>
> I would just collect all the columns in a `Array{Float64,1}[]` array and
> then call `hcat(x...)` on the result.
>
> a_temp = Array{Float64,1}[]
> b_temp = Array{Float64,1}[]
> k = 1
> while isfile("data$k.csv")
> data = readcsv("data$k.csv")
> push!(a_tmp, data[:,1])
> push!(b_tmp, data[:,2])
> k += 100 # thin the chain by 100
> end
> a = hcat(a_tmp...)
> b = hcat(b_tmp...)
>
> It would also work just as fine with `Any[]` (or `{}`) as the temporary
> collection, but if you know the type, it I like write the type for
> documentation.
>
> Ivar
>
> kl. 02:43:37 UTC+1 lørdag 1. mars 2014 skrev Ethan Anderes følgende:
>>
>> Hi Folks:
>>
>> Newbie here...
>>
>> I often need to write code that iteratively reads files which are saved
>> from a long MCMC chain. Coming from Matlab I always try the following
>>
>>
>> a = []
>> b = []
>> k = 1
>> while isfile("data$k.csv")
>> data = readcsv("data$k.csv")
>> a = [a data[:,1]]
>> b = [b data[:,2]]
>> k += 100 # thin the chain by 100
>> end
>>
>> This doesn't seem to work in julia. Does anyone have any recommendations
>> on how to accomplish this in a nice julian way? Here is one example:
>>
>>
>> a = Array(Float64,512,0)
>> b = Array(Float64,512,0)
>> k = 1
>> while isfile("data$k.csv")
>> data = readcsv("data$k.csv")
>> a = [a data[:,1]]
>> b = [b data[:,2]]
>> k += 100
>> end
>>
>> I would like to avoid this since it requires me to know I have 512 rows
>> ahead of time. Of course, I could always do this
>>
>>
>> data = readcsv("data1.csv")
>> a = data[:,1]
>> b = data[:,2]
>> k = 101
>> while isfile("data$k.csv")
>> data = readcsv("data$k.csv")
>> a = [a data[:,1]]
>> b = [b data[:,2]]
>> k += 100
>> end
>>
>> ...but its not as clean.
>>
>>