Re: [julia-users] Re: equivalent of numpy newaxis?

2016-09-13 Thread DNF
Oh, yeah. I forgot that .+, .-, etc are not along for the ride yet. I understand it is pretty much ready for inclusion in 0.6. There is also a one extra allocation, namely y.', which would not be necessary in a loop. But this is hardly worse than numpy, right? On Tuesday, September 13, 2016

[julia-users] Re: equivalent of numpy newaxis?

2016-09-13 Thread Neal Becker
So you're saying that abs2.(x .- y.') will not allocate a 2d array and then pass to abs2? That's great! But how would I know that? DNF wrote: > For your particular example, it looks like what you want is (and I am just > guessing what mag_sqr means): > dist = abs2.(x .- y.') > The performance

[julia-users] Re: equivalent of numpy newaxis?

2016-09-12 Thread DNF
For your particular example, it looks like what you want is (and I am just guessing what mag_sqr means): dist = abs2.(x .- y.') The performance should be the similar to a hand-written loop on version 0.5. You can read about it here:

Re: [julia-users] Re: equivalent of numpy newaxis?

2016-09-12 Thread Bob Nnamtrop
I use a simple function for this: function newdim(A::AbstractArray, d::Integer) @assert 0 < d <= ndims(A)+1 dim = size(A) reshape(A, dim[1:d-1]..., 1, dim[d:end]...) end But having syntax for a newaxis would be great. See also: https://github.com/JuliaLang/julia/issues/5405

Re: [julia-users] Re: equivalent of numpy newaxis?

2016-09-12 Thread Tim Holy
*julia> a = rand(3)* *3-element Array{Float64,1}:* *0.47428 * *0.505429* *0.198919* *julia> reshape(a, (3,1))* *3×1 Array{Float64,2}:* *0.47428 * *0.505429* *0.198919* *julia> reshape(a, (1,3))* *1×3 Array{Float64,2}:* *0.47428 0.505429 0.198919* Is that what you want? (Note that

[julia-users] Re: equivalent of numpy newaxis?

2016-09-12 Thread Neal Becker
I haven't studied it, but I guess that newaxis increases the dimensionality, while specifying 0 for the stride. Can reshape do that? Tim Holy wrote: > I'm not certain I understand what `np.newaxis` does, but doesn't `reshape` > do the same thing? (newaxis does look like a convenient way to

[julia-users] Re: equivalent of numpy newaxis?

2016-09-12 Thread Matt Bauman
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