|
1 | 1 | # numpydoc |
2 | 2 |
|
3 | | -## Example |
4 | | - |
5 | | -### Source |
6 | | - |
7 | | -``` |
8 | | -"""Docstring for the example.py module. |
9 | | -
|
10 | | -Modules names should have short, all-lowercase names. The module name may |
11 | | -have underscores if this improves readability. |
12 | | -
|
13 | | -Every module should have a docstring at the very top of the file. The |
14 | | -module's docstring may extend over multiple lines. If your docstring does |
15 | | -extend over multiple lines, the closing three quotation marks must be on |
16 | | -a line by itself, preferably preceded by a blank line. |
17 | | -
|
18 | | -""" |
19 | | -
|
20 | | -import os # standard library imports first |
21 | | -
|
22 | | -# Do NOT import using *, e.g. from numpy import * |
23 | | -# |
24 | | -# Import the module using |
25 | | -# |
26 | | -# import numpy |
27 | | -# |
28 | | -# instead or import individual functions as needed, e.g |
29 | | -# |
30 | | -# from numpy import array, zeros |
31 | | -# |
32 | | -# If you prefer the use of abbreviated module names, we suggest the |
33 | | -# convention used by NumPy itself:: |
34 | | -
|
35 | | -import numpy as np |
36 | | -import matplotlib as mpl |
37 | | -import matplotlib.pyplot as plt |
38 | | -
|
39 | | -# These abbreviated names are not to be used in docstrings; users must |
40 | | -# be able to paste and execute docstrings after importing only the |
41 | | -# numpy module itself, unabbreviated. |
42 | | -
|
| 3 | +Sphinx extension that provides support for the Numpy docstring format in Sphinx. |
43 | 4 |
|
44 | | -def foo(var1, var2, *args, long_var_name="hi", only_seldom_used_keyword=0, **kwargs): |
45 | | - r"""Summarize the function in one line. |
| 5 | +- **Documentation**: https://numpydoc.readthedocs.io/ |
| 6 | +- **Source Code**: https://github.com/numpy/numpydoc |
46 | 7 |
|
47 | | - Several sentences providing an extended description. Refer to |
48 | | - variables using back-ticks, e.g. `var`. |
49 | | -
|
50 | | - Parameters |
51 | | - ---------- |
52 | | - var1 : array_like |
53 | | - Array_like means all those objects -- lists, nested lists, etc. -- |
54 | | - that can be converted to an array. We can also refer to |
55 | | - variables like `var1`. |
56 | | - var2 : int |
57 | | - The type above can either refer to an actual Python type |
58 | | - (e.g. ``int``), or describe the type of the variable in more |
59 | | - detail, e.g. ``(N,) ndarray`` or ``array_like``. |
60 | | - *args : iterable |
61 | | - Other arguments. |
62 | | - long_var_name : {'hi', 'ho'}, optional |
63 | | - Choices in brackets, default first when optional. |
64 | | -
|
65 | | - Returns |
66 | | - ------- |
67 | | - type |
68 | | - Explanation of anonymous return value of type ``type``. |
69 | | - describe : type |
70 | | - Explanation of return value named `describe`. |
71 | | - out : type |
72 | | - Explanation of `out`. |
73 | | - type_without_description |
74 | | -
|
75 | | - Other Parameters |
76 | | - ---------------- |
77 | | - only_seldom_used_keyword : int, optional |
78 | | - Infrequently used parameters can be described under this optional |
79 | | - section to prevent cluttering the Parameters section. |
80 | | - **kwargs : dict |
81 | | - Other infrequently used keyword arguments. Note that all keyword |
82 | | - arguments appearing after the first parameter specified under the |
83 | | - Other Parameters section, should also be described under this |
84 | | - section. |
85 | | -
|
86 | | - Raises |
87 | | - ------ |
88 | | - BadException |
89 | | - Because you shouldn't have done that. |
90 | | -
|
91 | | - See Also |
92 | | - -------- |
93 | | - numpy.array : Relationship (optional). |
94 | | - numpy.ndarray : Relationship (optional), which could be fairly long, in |
95 | | - which case the line wraps here. |
96 | | - numpy.dot, numpy.linalg.norm, numpy.eye |
97 | | -
|
98 | | - References |
99 | | - ---------- |
100 | | - Cite the relevant literature, e.g. [1]_. You may also cite these |
101 | | - references in the notes section above. |
102 | | -
|
103 | | - .. [1] O. McNoleg, "The integration of GIS, remote sensing, |
104 | | - expert systems and adaptive co-kriging for environmental habitat |
105 | | - modelling of the Highland Haggis using object-oriented, fuzzy-logic |
106 | | - and neural-network techniques," Computers & Geosciences, vol. 22, |
107 | | - pp. 585-588, 1996. |
108 | | -
|
109 | | - Examples |
110 | | - -------- |
111 | | - These are written in doctest format, and should illustrate how to |
112 | | - use the function. |
113 | | -
|
114 | | - >>> a = [1, 2, 3] |
115 | | - >>> print([x + 3 for x in a]) |
116 | | - [4, 5, 6] |
117 | | - >>> print("a\nb") |
118 | | - a |
119 | | - b |
120 | | - """ |
121 | | - # After closing class docstring, there should be one blank line to |
122 | | - # separate following codes (according to PEP257). |
123 | | - # But for function, method and module, there should be no blank lines |
124 | | - # after closing the docstring. |
125 | | -``` |
126 | | - |
127 | | -### Rendered |
| 8 | +## Example |
128 | 9 |
|
129 | 10 | ```{raw} html |
130 | 11 | <p>Docstring for the example.py module.</p> |
|
0 commit comments