From 900e8b74a804d5ea738fdb9a4975bd23e8db2ef1 Mon Sep 17 00:00:00 2001 From: David Hassell Date: Thu, 10 Mar 2022 10:10:22 +0000 Subject: [PATCH] Add docstring examples --- cf/data/data.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/cf/data/data.py b/cf/data/data.py index e11bf75262..87dcde9e68 100644 --- a/cf/data/data.py +++ b/cf/data/data.py @@ -9114,7 +9114,27 @@ def ndindex(self): `itertools.product` An iterator over tuples of indices of the data array. - **Examples:** + **Examples** + + >>> d = cf.Data(np.arange(6).reshape(2, 3)) + >>> print(d.array) + [[0 1 2] + [3 4 5]] + >>> for i in d.ndindex(): + ... print(i, d[i]) + ... + (0, 0) [[0]] + (0, 1) [[1]] + (0, 2) [[2]] + (1, 0) [[3]] + (1, 1) [[4]] + (1, 2) [[5]] + + >>> d = cf.Data(9) + >>> for i in d.ndindex(): + ... print(i, d[i]) + ... + () 9 """ return product(*[range(0, r) for r in self.shape])