▲ | fifilura 10 hours ago | ||||||||||||||||||||||
Doing Python or R right means using vector/matrix operations in e.g. numpy. Those will be faster. Just think twice before using a for loop. Most of the time it is not needed. | |||||||||||||||||||||||
▲ | nickforr 7 hours ago | parent | next [-] | ||||||||||||||||||||||
If you write the R code using vectorised operations it’s significant orders of magnitude faster (148 seconds to 1.5 milliseconds on posit.cloud). The nested loop becomes: j <- sum((seq_len(100000) - 1) %% u) a <- a + j + r | |||||||||||||||||||||||
▲ | MooseBurger 10 hours ago | parent | prev [-] | ||||||||||||||||||||||
I disagree w.r.t. python. You shouldn't need a numerical computing library to do a for loop generally. | |||||||||||||||||||||||
|