1

I'm having a trouble understanding the concept of Axis elimination in numpy. Suppose I have the following 2D matrix:

A = 

1 2 3

3 4 5

6 7 8

Ok I understand that sum(A, axis=0) will sum each column down and will give a 1D array with 3 elements. I also understand that sum(A, axis=1) will sum each row.

But my trouble is when I read that axis=0 eliminates the 0th axis and axis=1 eliminates the 1th axis. Also sometime people mention "reduce" instead of "eliminate". I'm unable to understand what does that eliminate. For example sum(A, axis=0) will sum each column from top to bottom, but I don't see elimination or reduction here. What's the point? The same also for sum(A,axis=1).

AND how is it for higher dimensions?

p.s. I always confused between matrix dimensions and array dimensions. I wished that people who write the numpy documentation makes this distinction very clear.

Jack Twain
  • 6,273
  • 15
  • 67
  • 107
  • 1
    where did you encounter the term "elimination"? where did you encounter "reduce"? you'd have to be clearer about what exactly you don't understand... questions like "what's the point?" are unlikely to result with answers in this site... – shx2 Mar 01 '14 at 20:36
  • @shx2 http://stackoverflow.com/a/22115471/2464658 – Jack Twain Mar 02 '14 at 08:11

1 Answers1

0

http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.reduce.html

Reduces a‘s dimension by one, by applying ufunc along one axis.

For example, add.reduce() is equivalent to sum().

In numpy, the base class is ndarray - a multidimensional array (can 0d, 1d, or more)

http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html

Matrix is a subclass of array http://docs.scipy.org/doc/numpy/reference/arrays.classes.html

Matrix objects are always two-dimensional

The history of the numpy Matrix is old, but basically it's meant to resemble the MATLAB matrix object. In the original MATLAB nearly everything was a matrix, which was always 2d. Later they generalized it to allow more dimensions. But it can't have fewer dimensions. MATLAB does have 'vectors', but they are just matrices with one dimension being 1 (row vector versus column vector).

'axis elimination' is not a common term when working with numpy. It could, conceivably, refer to any of several ways that reduce the number of dimensions of an array. Reduction, as in sum(), is one. Indexing is another: a[:,0,:]. Reshaping can also change the number of dimensions. np.squeeze is another.

Community
  • 1
  • 1
hpaulj
  • 221,503
  • 14
  • 230
  • 353