Commit df777fd3 authored by Matthias Bussonnier's avatar Matthias Bussonnier Committed by Anne Fouilloux

Update some docstring sections to use numpy standard. (#729)

* Update some docstring sections to use numpy standard.

You will also see that some of the information was incorrect due to
multiple update. The function used to be called `center` and to return
a list instead of a numpy array. So the help and example were incorrect.

The use of the numpy standard is a good practice; as most projects use
it. Even if we don't expect users to remember it; at least they are made
aware that there is standard and can look for it.

This also mirror the documentation style of loadtxt that is seen later
in the lesson.

And finally sphinx can understand numpydoc and generate nice HTML pages.
So all in all I believe this is a nice detail to add to the lesson.

* Use minimal numpy docstring with only example.
parent ac08a578
......@@ -374,7 +374,12 @@ we can break the string across multiple lines:
def offset_mean(data, target_mean_value):
'''Return a new array containing the original data
with its mean offset to match the desired value.
Example: offset_mean([1, 2, 3], 0) => [-1, 0, 1]'''
Examples
--------
>>> offset_mean([1, 2, 3], 0)
array([-1., 0., 1.])
'''
return (data - numpy.mean(data)) + target_mean_value
help(offset_mean)
......@@ -385,8 +390,13 @@ help(offset_mean)
Help on function offset_mean in module __main__:
offset_mean(data, target_mean_value)
Return a new array containing the original data with its mean offset to match the desired value.
Example: offset_mean([1, 2, 3], 0) => [-1, 0, 1]
Return a new array containing the original data
with its mean offset to match the desired value.
Examples
--------
>>> offset_mean([1, 2, 3], 0)
array([-1., 0., 1.])
~~~
{: .output}
......@@ -443,9 +453,14 @@ let's re-define our `offset_mean` function like this:
~~~
def offset_mean(data, target_mean_value=0.0):
'''Return a new array containing the original data with its mean offset to match the
desired value (0 by default).
Example: offset_mean([1, 2, 3], 0) => [-1, 0, 1]'''
'''Return a new array containing the original data
with its mean offset to match the desired value, (0 by default).
Examples
--------
>>> offset_mean([1, 2, 3])
array([-1., 0., 1.])
'''
return (data - numpy.mean(data)) + target_mean_value
~~~
{: .language-python}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment