0

I've been working with numpy and pandas for a long time but I'm still usually confused by the concept of doing an operation along an axis.

For example, if I have a data of shape [200,5], and I want to find the mean with the resulting shape [1,5], I would first call data.mean(axis=0), and if it doesn't work, I would try data.mean(axis=1).

Turns out, axis=0 is correct in this case. But I don't have good terminology for me to remember which axis to use.

Currently, I think that whatever axis I want to reduce the shape to 1, I will need to apply the operation on that axis. This works fine for Reduction operation like mean, sum or std.

But I don't know how to think when I would like to apply operations that do not reduce the shape like divide, add, sort, etc. (For divide and add of different shapes, broadcasting is involved)

So it made me curious about how the guy who created pandas and numpy think intuitively about this. It made curious about what they exactly mean when they say "sorting along the row axis".

I want to understand it so clear that I know what results I'm going to expect when I call a certain axis!

off99555
  • 3,797
  • 3
  • 37
  • 49
  • You're better off searching for information on google yourself than hoping someone will rehash what has already been said countless times by now. – cs95 Dec 12 '18 at 18:18
  • In a 2d array this can be confusing (even for me). But it is clearer if I look at a 1d - the sum applies to that one axis. Or a 3d where the sum applies to one, but leaves the other two. But as you say it's more obvious when dealing with reduce operations. – hpaulj Dec 12 '18 at 18:23
  • I've tried searching of course. When I don't find it, so I asked. What is so wrong about asking stuff? – off99555 Dec 12 '18 at 18:23
  • And the thread that you attached is similar to mine. But I haven't found it with my wording when I searched Google. And most importantly, it's not about operations that do not reduce the shape. So it does not apply for me. I already know most of the stuff they said there. – off99555 Dec 12 '18 at 18:25
  • 1
    Confusion like this is why I keep a Ipython session open - to test code snippets. I'm not particularly happy with the duplicate. It goes into a lot of detail, where as I think the OP wants a more intuitive answer. – hpaulj Dec 12 '18 at 18:28

0 Answers0