I just happen to see this example but the original post has been closed by @StefanKarpinski . As I saw many vips in this forum like this particular example I feel a little confused because the R code is not really a good one.
- No need to use
sapply. Given a 1-row matrix b,
matrix(sapply(b, function(x) rep(x, 4)), nrow = 4)
is just same as
matrix(rep(b, each = 4), nrow = 4).
- IMO, the quoted example just shows the operator
^in R-base is not vectorized. I don’t know the exact reason but one can easily overwrite the default if he/she need do
matrix ^ matrixelement-wise.
Please don’t get me wrong: I don’t want to reopen the original post, nor compare broadcasting in Julia with R. I come from R but would like to spend time on learning Julia.