Would 
a1 = cat(3, a)

do what you want?

Den mandag den 11. januar 2016 kl. 09.03.57 UTC+1 skrev Doug Y'barbo:
>
> apologies if this topic has been asked and answered; lack of distinctive 
> terms gave me large result sets from my queries of this archive
>
> it's common for me to want to add an axis to a Julia array, usually as a 
> predicate to broadcasting, or more precisely to modify two arrays so that 
> their trailing dimensions are equal and therefore invoke the Julia 
> compiler's own broadcasting.
>
> to be clear, i'm not talking about a very specific transformation--one 
> that doesn't change the Array's length and that can be reversed by calling 
> *squeeze*
>
> this is how i do it just now:
>
>    
> a = rand(4, 3)
>  
> a1 = reshape(a, 4, 1, 3) 
>
> what i would like to do is something like NumPy (which of course also has 
> a reshape method, but it likely wouldn't be used for this purpose)
>
> a1 = [:,NP.newaxis,:]
>
> to me this is much better because a1 is a view, rather than a copy, and i 
> never had to pass in the values for the other dimensions, which is 
> inconvenient and error-prone. (The two expressions for a1 are both valid 
> NumPy and are equivalent).
>
> i would bet that Julia has a built-in similar to NumPy's to do what i 
> want, i just can't find it
>
> --doug
>
>
>
>

Reply via email to