From 18594cd9653a865fddfa4cd81f82ab54430be1c9 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Tue, 28 Oct 2008 00:13:44 +0000 Subject: Import documentation from doc wiki (part 2, work-in-progress docstrings, but they are still an improvement) --- numpy/lib/index_tricks.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'numpy/lib/index_tricks.py') diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index 02018c87e..3021635dc 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -20,8 +20,6 @@ def unravel_index(x,dims): """ Convert a flat index into an index tuple for an array of given shape. - e.g. for a 2x2 array, unravel_index(2,(2,2)) returns (1,0). - Parameters ---------- x : int @@ -31,25 +29,26 @@ def unravel_index(x,dims): Notes ----- - Since x.flat[p] == x.max() it may be easier to use flattened indexing - than to re-map the index to a tuple. + In the Examples section, since ``arr.flat[x] == arr.max()`` it may be + easier to use flattened indexing than to re-map the index to a tuple. Examples -------- - >>> x = np.ones((5,4)) - >>> x + >>> arr = np.ones((5,4)) + >>> arr array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11], [12, 13, 14, 15], [16, 17, 18, 19]]) - >>> p = x.argmax() - >>> p + >>> x = arr.argmax() + >>> x 19 - >>> idx = np.unravel_index(p, x.shape) + >>> dims = arr.shape + >>> idx = np.unravel_index(x, dims) >>> idx (4, 3) - >>> x[idx] == x.max() + >>> arr[idx] == arr.max() True """ -- cgit v1.2.1