Try the cat, hcat, vcat family of functions.
--Tim

On Saturday, April 04, 2015 05:04:21 PM Tamas Papp wrote:
> Hi,
> 
> Suppose I have a function that maps an atom of type T, eg Float64, into
> Vector{T}, and takes another argument n that determines its length.
> 
> What is the idiomatic/fast way of collecting the values in the columns
> of a matrix?
> 
> Currently I am using this:
> 
> @doc """Map elements of `x` into columns of a matrix using `f`.
> Result is assumed to have the same element type as `x`.""" ->
> function maptocols{T}(f,x::Vector{T},n)
>   k = length(x)
>   b = Array(T, n, k)
>   for j = 1:k
>     b[:,j] = f(x[j],n)
>   end
>   b
> end
> 
> Eg
> 
> julia> maptocols((x,n) -> x.*[1:n;], [1,2,3,4], 4)
> 4x4 Array{Int64,2}:
>  1  2   3   4
>  2  4   6   8
>  3  6   9  12
>  4  8  12  16
> 
> which is OK but of course I would prefer a one-liner if there is one
> provided by the language (could not find it though).
> 
> Best,
> 
> Tamas

Reply via email to