I am struggling to use the dot operator/ broadcasting correctly though when I’d like to broadcast across columns of a matrix.
Suppose I have a function:
function myfun(col_vec, scalar) #does something complex operation ... return output end
I’d like a ``vector" version that operates on a matrix by column:
function myfun_vec(mat, vec) out = length(output) for ix = 1:length(vec) out[ix] = myfun(mat[:, ix], vec[ix]) end out end
Can I use dot syntax / broadcasting to avoid implementing myfun_vec instead? Note
myfun. ( mat, vec)
does not return what I want. I mostly want the “.” version so that I can write things like:
myfun. (mat, 2) #should return myfun_vec(mat, 2 * ones(dim(mat, 2) )
If redefine the data structure of mat to be a vector of vectors and then everything works fine, but that seems super cludgey and doesn’t match surrounding code.