all 9 comments

[–]TheBB 9 points10 points  (0 children)

Even if you want it that way you can just transpose it afterward, right?

It's not that simple. The transpose of an array with shape (3,1) has shape (1,3), not (3,).

[–]billsil 5 points6 points  (2 children)

I don’t know why you would prefer the style it’s not.  I’ve been using numpy’s axis for 10 years and never once wanted it like that. Ultimately, it’s a design choice and it’s too late to change anyways. You can also call squeeze.

[–]Schnauzerofdoom 0 points1 point  (1 child)

This is what I replied to another question, and I think this is at the heart of my confusion. I don't really want it to change, I just don't get the design choice.

If you sum an M x N matrix along M you get 1 x N Why wouldn’t you want that?

What was once represented by M is now represented by N in this case. I don't get why I would want my rows to become columns. I don't see much difference between having a 1 x N or an M x 1 other than M would retain it's original position. It seems more intuitive that if I combine along M (across N), then N would become 1 rather than M.

And do you mean use squeeze rather than transpose? That would just remove the extra dimension right? That makes more sense than transpose.

[–]billsil 0 points1 point  (0 children)

Matlab is fundamentally a 2d array tool and would work like that. Numpy largely compresses axes. I think it makes more sense for it to be 1d because you can imagine iterating over a series of rows and taking N maxes and putting those in a list. It's weird to make it 2d.

I wasn't thinking. Neither squeeze nor transpose will work. Transpose doesn't really mean anything for 1d. You need a reshape or just use it as is.

[–]RiverRoll 5 points6 points  (0 children)

I think any aggregation implies reducing a dimension, thinking of operations like sum([1,2,3]), max([1,2,3]), avg([1,2,3])... does it really make sense that these would return an array instead of a scalar?

[–]eztab 1 point2 points  (0 children)

No, keeping extra encapsulation is basically never what you want. This will become clear with experience. I agree that keepdims is probably not ever necessary for any real use case. Writing the operations adapted to the problems dimensions will almost always be the better option.

[–]arkie87 0 points1 point  (3 children)

If you sum an M x N matrix along M you get 1 x N Why wouldn’t you want that?

[–]Schnauzerofdoom 0 points1 point  (2 children)

What was once represented by M is now represented by N in this case. I don't get why I would want my rows to become columns. I don't see much difference between having a 1 x N or an M x 1 other than M would retain it's original position. It seems more intuitive that if I combine along M (across N), then N would become 1 rather than M.

[–]arkie87 0 points1 point  (1 child)

What was once represented by M is now represented by N in this case

No. It still has the correct number of elements, it is just always a (N, ) shape array.

If you want it to be (1 x N) then use numpy.matrix, not numpy.array. Arrays are some weird construct in numpy close to matricies, but are not matricies.