@@ -34,6 +34,8 @@ Steps 2 and 3 are repeated until the assignments no longer change.
3434A possible implementation with pure Python could look like this:
3535
3636.. literalinclude :: py_kmeans.py
37+ :caption: py_kmeans.py
38+ :name: py_kmeans.py
3739
3840We can create sample data with:
3941
@@ -132,7 +134,9 @@ repetitive operations into compiled code to avoid slow loops.
132134With NumPy we can do without some loops:
133135
134136.. literalinclude :: np_kmeans.py
135- :lines: 1-8
137+ :caption: np_kmeans.py
138+ :name: np_kmeans.py
139+ :lines: 1-8
136140
137141The advantages of NumPy are that the Python overhead only occurs per array and
138142not per array element. However, because NumPy uses a specific language for array
@@ -149,7 +153,9 @@ Special data structures
149153 This way you can also bypass the loop in the ``compute_centers `` method:
150154
151155 .. literalinclude :: pd_kmeans.py
152- :lines: 2-4, 11-15
156+ :caption: pd_kmeans.py
157+ :name: pd_kmeans.py
158+ :lines: 2-4, 11-15
153159
154160`scipy.spatial <https://docs.scipy.org/doc/scipy/reference/spatial.html >`_
155161 for spatial queries like distances, nearest neighbours, k-Means :abbr: `etc
@@ -158,7 +164,9 @@ Special data structures
158164 Our ``find_labels `` method can then be written more specifically:
159165
160166 .. literalinclude :: sp_kmeans.py
161- :lines: 4-10
167+ :caption: sp_kmeans.py
168+ :name: sp_kmeans.py
169+ :lines: 4-10
162170
163171`scipy.sparse <https://docs.scipy.org/doc/scipy/reference/sparse.html >`_
164172 `sparse matrices <https://en.wikipedia.org/wiki/Sparse_matrix >`_
@@ -214,7 +222,9 @@ cumbersome.
214222Our example could then look like this:
215223
216224.. literalinclude :: cy_kmeans.pyx
217- :lines: 1-28
225+ :caption: cy_kmeans.pyx
226+ :name: cy_kmeans.pyx
227+ :lines: 1-28
218228
219229.. seealso ::
220230 * `Cython Tutorials
@@ -227,7 +237,9 @@ Numba
227237scientific Python and NumPy code into fast machine code, for example:
228238
229239.. literalinclude :: nb_kmeans.py
230- :lines: 1-25
240+ :caption: nb_kmeans.py
241+ :name: nb_kmeans.py
242+ :lines: 1-25
231243
232244However, Numba requires `LLVM <https://en.wikipedia.org/wiki/LLVM >`_ and some
233245Python constructs are not supported.
@@ -263,7 +275,9 @@ can distribute tasks in a cluster. In doing so, they have different focuses:
263275Our example could look like this with Dask:
264276
265277.. literalinclude :: ds_kmeans.py
266- :lines: 1-32
278+ :caption: ds_kmeans.py
279+ :name: ds_kmeans.py
280+ :lines: 1-32
267281
268282.. toctree ::
269283 :hidden:
0 commit comments