It's pretty close. In Julia 0.5, we have all the parts that are required to 
make this a possibility.  We have index types that specify both how many 
indices in the source array should be consumed (CartesianIndex{N} spans N 
dimensions) and types that determine what the dimensionality of the output 
should be (the dimensionality of the result is the sum of the 
dimensionalities of the indices).

That means that we now know exactly what the Julia equivalent of 
`np.newaxis` should be: [CartesianIndex{0}()].  This is really cool, and 
something I never considered before.

We're not quite there yet; views don't fully support CartesianIndices (fix 
in progress), and indexing by default creates a copy.

On Monday, September 12, 2016 at 2:29:15 PM UTC-5, Neal Becker wrote:
>
> Some time ago I asked this question 
>
> http://stackoverflow.com/questions/25486506/julia-broadcasting-equivalent-of-numpy-newaxis
>  
>
> As a more interesting example, here is some real python code I use: 
> dist = mag_sqr (demod_out[:,np.newaxis] - const.map[np.newaxis,:]) 
>
> where demod_out, const.map are each vectors, mag_sqr performs element-wise 
> euclidean distance, and the result is a 2D array whose 1st axis matches 
> the 
> 1st axis of demod_out, and the 2nd axis matches the 2nd axis of const.map. 
>
>
> From the answers I've seen, julia doesn't really have an equivalent 
> functionality.  The idea here is, without allocating a new array, 
> manipulate 
> the strides to cause broadcasting. 
>
> AFAICT, the best for Julia would be just forget the vectorized code, and 
> explicitly write out loops to perform the computation.  OK, I guess, but 
> maybe not as readable. 
>
> Is there any news on this front? 
>
>

Reply via email to