A mean docstring?
Fernando Perez
fperez.net at gmail.com
Tue Oct 10 14:33:36 CDT 2006
Hi all,
I was updating some old Numeric code to be more 'numpythonic' (it
works, but uses a lot of Numeric-style cruft), and read the a.mean()
docstring that says:
If axis is None, this equals:
a.sum(axis, dtype) * 1.0 / product(a.shape,axis=0)
Is this convoluted form of the denominator really needed? Isn't it
equivalent to a.size? A few quick tests (and my understanding of
numpy's new attributes) seem to indicate so:
In [78]: a=rand(1,2,3,4); product(a.shape,axis=0)==a.size
Out[78]: True
In [79]: a=rand(2,3,4,2); product(a.shape,axis=0)==a.size
Out[79]: True
In [80]: a=rand(2); product(a.shape,axis=0)==a.size
Out[80]: True
In [81]: a=rand(2,4,4); product(a.shape,axis=0)==a.size
Out[81]: True
So my question is two-fold (assuming the above is correct in all cases):
1. Should the docstring be changed to simply say
If axis is None, this equals:
a.sum(axis, dtype) * 1.0 / a.size
This is clearer to readers, and promotes the use of .size as a quick
and correct way of getting an array's size.
2. Does the implementation actually used the more complicated
product() approach, or does it just read .size? I'm wondering about
efficiency.
Regards,
f
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
More information about the Numpy-discussion
mailing list