On Tuesday, May 20, 2014 07:22:51 PM Paul Analyst wrote: > I have arrays about 10k*10k. Is faster by loop?
I think you'll find that loops are a generic answer to many of the questions you've asked on this list. While in some languages loops are slow and you _have_ to know about and use some high-level function to get good performance, that doesn't apply to Julia. Indeed, many of Julia's high-level functions are written in terms of plain, entirely non-magical loops. Loops you write yourself will generally be just as fast (though keep the "performance tips" section of the manual firmly in mind). Indeed, sometimes the loop is better than the high-level function, because you can do your calculation without creating temporaries. Once you get used to this idea, I think you'll find it very freeing, because you don't need to know about some clever way to leverage a high-level function; if the calculation is very simple (as it is here), just write a 3 line loop and move on. Best, --Tim > Paul > > W dniu 2014-05-20 17:18, Oliver Lylloff pisze: > > Yes, and for larger arrays it might be beneficial to write in a loop: > > > > a = rand(1000); > > b = rand(1000,1000); > > for i = 1:length(a) > > > > b[i,i] = b[i,i] + a[i]; > > > > end > > > > Den tirsdag den 20. maj 2014 16.48.30 UTC+2 skrev paul analyst: > > b- not is zeros sometimes... > > c= diagm(a) > > b=b+c. > > Thx > > Paul > > > > W dniu wtorek, 20 maja 2014 16:17:11 UTC+2 użytkownik Oliver > > > > Lylloff napisał: > > Hi Paul, > > > > if b is just zeros, then b = diagm(a). > > > > Best, > > Oliver > > > > Den tirsdag den 20. maj 2014 15.04.33 UTC+2 skrev paul analyst: > > a=rand(5) > > b=zeros(5,5) > > how to apply a on diagonal b ? > > Paul