Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reducer behaviour not consistent over 1-dimensional arrays #32878

Closed
aahaselgrove opened this issue Aug 13, 2019 · 2 comments
Closed

Reducer behaviour not consistent over 1-dimensional arrays #32878

aahaselgrove opened this issue Aug 13, 2019 · 2 comments

Comments

@aahaselgrove
Copy link

aahaselgrove commented Aug 13, 2019

I was looking at #16606 this morning and am not 100% on-board with the dropdims solution - as commented by others, I feel like it obfuscates the purpose of the code, which is performing the reduction.

I just noticed that, working with a 1-dimensional array, a reduction gives me a single value, automatically dropping the dimension. This seems inconsistent with behaviour for higher-dimensional arrays. Is this intended?

@StefanKarpinski
Copy link
Member

StefanKarpinski commented Aug 13, 2019

Thanks for the report. However, the behavior is consistent and has nothing to do with the dimensionality of the input: reducers without the dims keyword argument return a scalar:

julia> A = rand(3, 4)
3×4 Array{Float64,2}:
 0.195413  0.543549  0.63676   0.872648
 0.931781  0.892374  0.233773  0.0597087
 0.48907   0.896954  0.317274  0.676223

julia> sum(A)
6.745528428752973

julia> sum(A, dims=(1,2))
1×1 Array{Float64,2}:
 6.745528428752973

@mbauman
Copy link
Member

mbauman commented Aug 13, 2019

Yes, this is intended. For the vector case specifically, it's:

julia> sum(ones(3))
3.0

julia> sum(ones(3), dims=1)
1-element Array{Float64,1}:
 3.0

@mbauman mbauman closed this as completed Aug 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants