Hi Mike,
One way of obtaining what you want, using your own construction, is:
*vcat(map(row->a[row,:]+1, 1:size(a)[1])...)*
another way would be to use mapslices(), or write a loop, or use matrix
calculations, all depending a bit on what your operation on the row is.
(It may be faster to access the data in the matrix by column, so you might
want to reorganize the data in that case.
---david
On Sunday, November 30, 2014 11:11:38 PM UTC+1, Michael Mayo wrote:
>
> Hi,
>
> How do I use map or pmap in Julia to apply a function each row of a 2D
> matrix and get back a 2D matrix with each row appropriately updated?
> Currently, map returns an array of 1D arrays instead of a 2D array, e.g.:
>
> *julia> **a=rand(5,3)*
>
> *5x3 Array{Float64,2}:*
>
> * 0.0970387 0.944568 0.589086 *
>
> * 0.477571 0.916078 0.0674227*
>
> * 0.424044 0.827748 0.49385 *
>
> * 0.691055 0.0370019 0.845552 *
>
> * 0.686033 0.812021 0.222669 *
>
>
> *julia> **map(row->a[row,:]+1, 1:size(a)[1])*
>
> *5-element Array{Array{Float64,2},1}:*
>
> * 1x3 Array{Float64,2}:*
>
> * 1.09704 1.94457 1.58909*
>
> * 1x3 Array{Float64,2}:*
>
> * 1.47757 1.91608 1.06742*
>
> * 1x3 Array{Float64,2}:*
>
> * 1.42404 1.82775 1.49385*
>
> * 1x3 Array{Float64,2}:*
>
> * 1.69106 1.037 1.84555 *
>
> * 1x3 Array{Float64,2}:*
>
> * 1.68603 1.81202 1.22267*
>
>
> Although I could probably post-process the output of map back into a 2D
> array, is there is a more elegant way of doing it?
>
>
> Mike
>