[Numpy-discussion] inconsistent use of axis= keyword argument?

Travis Oliphant oliphant.travis at ieee.org
Thu Feb 23 12:26:06 EST 2006


Vidar Gundersen wrote:

>(i've been updating the cross reference of MATLAB synonymous
>commands in Numeric Python to NumPy. I've kept Numeric/numarray
>alternatives in the source XML, but omitted it in the PDF outputs.
>see, http://37mm.no/download/matlab-python-xref.pdf.
>feedback is highly appreciated.)
>
>
>as i was working on this, i started wondering why 
>
>a.max(0), a.min(0), a.ptp(0), a.flatten(0), ...
>
>does not allow the axis=0 keyword argument used with
>the exact same meaning for:
>  
>

It's actually consistent.  These only have a single argument and so 
don't use keywords.   But, I can see now that it might be nice to have 
keywords even if there is only one argument. 

Feel free to submit a patch.

>m.mean(axis=0), m.sum(axis=0), ...
>  
>

These have multiple arguments, so the keywords are important.

>
>and i also wonder why concatenate can't be used to stack 1-d
>arrays on top of each other, returning a 2-d array?
>axis relates to the number of axes in the original array(s)?
>  
>
Because it's ambiguous what you mean to do.  1-d arrays only have a 
single axis.  How do you propose to tell concatenate to alter the shape 
of the output array and in what direction?  We've left it to the user to 
do that, like you do in the second example.

When you have more than one dimension on input, then it is clear what 
you mean by "stack" along an axis.  With only one-dimension, it isn't 
clear what is meant.






More information about the NumPy-Discussion mailing list