Browse files

DOC: Add a note about None values in the average documentation (#1180)

It was suggested in issue #1180 to add an ignore_None= parameter to
average, but I think this does not fit cleanly into NumPy, and rather
educating users about Python list comprehensions is better. This is
an attempt to do that.
  • Loading branch information...
1 parent fb486c6 commit ac2c160c5b0ad5a420543b94a1896f5e45f67b97 @mwiebe mwiebe committed Mar 25, 2011
Showing with 15 additions and 0 deletions.
  1. +15 −0 numpy/lib/
@@ -421,6 +421,21 @@ def average(a, axis=None, weights=None, returned=False):
When the length of 1D `weights` is not the same as the shape of `a`
along axis.
+ Notes
+ -----
+ When the array `a` contains `None` values, this function will throw
+ an error. If you would like to calculate the average without the `None`
+ values in the calculation, the `list comprehension`_ feature in Python
+ is a great way to do that. If you're new to Python, learning about
+ list comprehensions is well worth your while, as they make
+ manipulating and filtering lists very convenient.
+ .. _list comprehension:
+ >>> a = [1, None, 2, None]
+ >>> np.average([x for x in a if x != None])
+ 1.5
See Also

0 comments on commit ac2c160

Please sign in to comment.