summaryrefslogtreecommitdiff
path: root/numpy/add_newdocs.py
diff options
context:
space:
mode:
authorAllan Haldane <ealloc@gmail.com>2018-04-23 12:11:03 -0400
committerGitHub <noreply@github.com>2018-04-23 12:11:03 -0400
commitf2888dbfc440cc3023b751fb7a5d91b9817fc271 (patch)
tree67dc23a230c34c4881181c64661c6896b6bbf04a /numpy/add_newdocs.py
parentb5c1bcf1e8ef6e9c11bb4138a15286e648fcbce0 (diff)
parentac7d543f52ab50c878b64a13662dce198c6fcb64 (diff)
downloadnumpy-f2888dbfc440cc3023b751fb7a5d91b9817fc271.tar.gz
Merge pull request #10951 from mattip/nditer-close-fixes
BUG: it.close() disallows access to iterator, fixes #10950
Diffstat (limited to 'numpy/add_newdocs.py')
-rw-r--r--numpy/add_newdocs.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/numpy/add_newdocs.py b/numpy/add_newdocs.py
index 8e8339355..93a521658 100644
--- a/numpy/add_newdocs.py
+++ b/numpy/add_newdocs.py
@@ -257,6 +257,7 @@ add_newdoc('numpy.core', 'nditer',
dtypes : tuple of dtype(s)
The data types of the values provided in `value`. This may be
different from the operand data types if buffering is enabled.
+ Valid only before the iterator is closed.
finished : bool
Whether the iteration over the operands is finished or not.
has_delayed_bufalloc : bool
@@ -282,7 +283,8 @@ add_newdoc('numpy.core', 'nditer',
Size of the iterator.
itviews
Structured view(s) of `operands` in memory, matching the reordered
- and optimized iterator access pattern.
+ and optimized iterator access pattern. Valid only before the iterator
+ is closed.
multi_index
When the "multi_index" flag was used, this property
provides access to the index. Raises a ValueError if accessed
@@ -292,7 +294,8 @@ add_newdoc('numpy.core', 'nditer',
nop : int
The number of iterator operands.
operands : tuple of operand(s)
- The array(s) to be iterated over.
+ The array(s) to be iterated over. Valid only before the iterator is
+ closed.
shape : tuple of ints
Shape tuple, the shape of the iterator.
value
@@ -331,12 +334,12 @@ add_newdoc('numpy.core', 'nditer',
it = np.nditer([x, y, out], [],
[['readonly'], ['readonly'], ['writeonly','allocate']])
+ with it:
+ while not it.finished:
+ addop(it[0], it[1], out=it[2])
+ it.iternext()
- while not it.finished:
- addop(it[0], it[1], out=it[2])
- it.iternext()
-
- return it.operands[2]
+ return it.operands[2]
Here is an example outer product function::
@@ -351,7 +354,7 @@ add_newdoc('numpy.core', 'nditer',
with it:
for (a, b, c) in it:
mulop(a, b, out=c)
- return it.operands[2]
+ return it.operands[2]
>>> a = np.arange(2)+1
>>> b = np.arange(3)+1
@@ -374,7 +377,7 @@ add_newdoc('numpy.core', 'nditer',
while not it.finished:
it[0] = lamdaexpr(*it[1:])
it.iternext()
- return it.operands[0]
+ return it.operands[0]
>>> a = np.arange(5)
>>> b = np.ones(5)
@@ -430,6 +433,13 @@ add_newdoc('numpy.core', 'nditer', ('copy',
"""))
+add_newdoc('numpy.core', 'nditer', ('operands',
+ """
+ operands[`Slice`]
+
+ The array(s) to be iterated over. Valid only before the iterator is closed.
+ """))
+
add_newdoc('numpy.core', 'nditer', ('debug_print',
"""
debug_print()