El jueves, 18 de junio de 2015, 22:18:48 (UTC+2), Mauro escribió: > > I don't know why Y does not get its type inferred correctly. But you >
Array comprehensions in global scope never (?) have their types inferred. You can try putting the array comprehension inside a function -- this may (or may not) help. [Note that to avoid performance problems, you should in fact avoid as much as possible having *anything* global -- everything should be in a function.] David. > can do: > eltype(df[2])[df[i,2] for i in 1:size(df,1)] > > On Thu, 2015-06-18 at 20:21, SG <david...@gmail.com <javascript:>> wrote: > > #= This line adds functions to take > > an AR(2) model for US inflation > > =# > > > > using DataFrames > > > > function lag0(x,p) > > R::Int32=size(x,1) > > C::Int32=size(x,2) > > > > # Take the first R-p rows of matrix x > > x1=x[1:(R-p),:] > > return out=[zeros(p,C); x1] > > > > end > > > > > > #load inflation datatable > > #df=readtable("inflation.csv") > > > > df=DataFrame() > > df[:A]=1:8 > > df[:B]=10:17 > > > > ################################## > > # Way of converting DataArray to Array # > > ################################## > > Y=[df[i,2] for i in [1:size(df,1)]] > > > > ## >>>> type of (Y) is now "Any" > > > > > > T=size(Y,1) > > X=[ones(T,1) lag0(Y,1) lag0(Y,2)] > > inv(X'*X) > > > > ========================================================== > > > > Hi All, > > > > I am posting again the issue. I found when I create an Array as shown > > above, the type of Array > > changed to "Any" which is not acceptable for the base Inverse > function(an > > error occurred). > > I am wondering why Julia does not assume the type of original data, here > in > > the example, Int64. > > > > Many thanks, > > > > > > > > > > > > > > On Thursday, June 18, 2015 at 7:23:16 PM UTC+2, SG wrote: > >> > >> Thank you, I will cut it down and post it again soon. > >> > >> On Thursday, June 18, 2015 at 7:01:16 PM UTC+2, Stefan Karpinski wrote: > >>> > >>> I think these sample programs may be too big for people to review for > >>> you. If you can pare the problem down to an example that can be posted > in > >>> an email, you've more likely to get help. > >>> > >>> On Thu, Jun 18, 2015 at 11:11 AM, SG <david...@gmail.com> wrote: > >>> > >>>> > >>>> Hi All, > >>>> > >>>> I am a novice to Julia. > >>>> > >>>> While I am running the attached julia program, I found "inverse" > >>>> function throws an error? > >>>> However it worked well in Matlab. Can you help me? Many thanks. > >>>> > >>>> > >>>> > >>>> > >>> > >