diff options
author | Matti Picus <matti.picus@gmail.com> | 2017-12-16 01:42:49 +0200 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-12-15 15:42:49 -0800 |
commit | 9d054c141b084546810486f91e763f3eb89af633 (patch) | |
tree | 93a3dbcf056628d078f775266bb4fafbd8a29aa5 /numpy/add_newdocs.py | |
parent | d233e1f4c176de8b1bf1365aac48caa10610a402 (diff) | |
download | numpy-9d054c141b084546810486f91e763f3eb89af633.tar.gz |
DOC: document nested_iters (#10078)
Diffstat (limited to 'numpy/add_newdocs.py')
-rw-r--r-- | numpy/add_newdocs.py | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py index 740396ff3..e0eeccb08 100644 --- a/numpy/add_newdocs.py +++ b/numpy/add_newdocs.py @@ -463,6 +463,67 @@ add_newdoc('numpy.core', 'nditer', ('reset', """)) +add_newdoc('numpy.core', 'nested_iters', + """ + Create nditers for use in nested loops + + Create a tuple of `nditer` objects which iterate in nested loops over + different axes of the op argument. The first iterator is used in the + outermost loop, the last in the innermost loop. Advancing one will change + the subsequent iterators to point at its new element. + + Parameters + ---------- + op : ndarray or sequence of array_like + The array(s) to iterate over. + + axes : list of list of int + Each item is used as an "op_axes" argument to an nditer + + flags, op_flags, op_dtypes, order, casting, buffersize (optional) + See `nditer` parameters of the same name + + Returns + ------- + iters : tuple of nditer + An nditer for each item in `axes`, outermost first + + See Also + -------- + nditer + + Examples + -------- + + Basic usage. Note how y is the "flattened" version of + [a[:, 0, :], a[:, 1, 0], a[:, 2, :]] since we specified + the first iter's axes as [1] + + >>> a = np.arange(12).reshape(2, 3, 2) + >>> i, j = np.nested_iters(a, [[1], [0, 2]], flags=["multi_index"]) + >>> for x in i: + ... print(i.multi_index) + ... for y in j: + ... print('', j.multi_index, y) + + (0,) + (0, 0) 0 + (0, 1) 1 + (1, 0) 6 + (1, 1) 7 + (1,) + (0, 0) 2 + (0, 1) 3 + (1, 0) 8 + (1, 1) 9 + (2,) + (0, 0) 4 + (0, 1) 5 + (1, 0) 10 + (1, 1) 11 + + """) + ############################################################################### |