[Numpy-discussion] why is default axis always different?

Sven Schreiber svetosch at gmx.net
Sat Aug 12 16:35:36 CDT 2006


Sven Schreiber schrieb:
> Hi,
> notice the (confusing, imho) different defaults for the axis of the
> following related functions:
> 
> nansum(a, axis=-1)
>     Sum the array over the given axis, treating NaNs as 0.
> 
> sum(x, axis=None, dtype=None)
>     Sum the array over the given axis.  The optional dtype argument
>     is the data type for intermediate calculations.
> 
> 
> average(a, axis=0, weights=None, returned=False)
>     average(a, axis=0, weights=None, returned=False)
> 
>     Average the array over the given axis.  If the axis is None, average
>     over all dimensions of the array.  Equivalent to a.mean(axis), but
>     with a default axis of 0 instead of None.
> 
>>>> numpy.__version__
> '1.0b2.dev2973'
> 
> Shouldn't those kind of functions have the same default behavior? So is
> this a bug or am I missing something?
> 
> Thanks for enlightenment,
> Sven
> 

Perhaps this is useful for others, so I'll share my self-enlightenment
(please correct me if I got it wrong):

- sum's axis=None default actually conforms to what's in the numpy 1.0
release notes (functions that match methods should also get their
default, which for such methods is axis=None)

- nansum's axis=-1 default is normal for functions which don't match
equivalent methods

- However, I still don't understand why then average() doesn't have
axis=-1 as its default like other functions...? Apparently the axis=0
default of average() is its main feature, explaining its existence
vis-à-vis .mean. But that seems inconsistent to me, as it breaks all the
rules: It doesn't conform to the standard axis=-1 default for functions,
and if it's viewed as equivalent to the .mean method (which it is), it
doesn't conform to the rule that it should share the latter's default
axis=None.

So imho it seems like there's no real use for average() other than
creating confusion. (Well that sounds a bit too strong, but anyway...) I
therefore suggest to officially deprecate it and move it to some
compatibility module. I'm going to file a corresponding ticket tomorrow
unless somebody tells me not to.

Cheers,
Sven





More information about the Numpy-discussion mailing list