diff options
author | Allan Haldane <ealloc@gmail.com> | 2018-04-21 16:38:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-21 16:38:28 -0400 |
commit | e0b5e8740efe6d42c909c1374494e614592c65ab (patch) | |
tree | f6c92cec21db0e0492c9a7a2ec715961a88b96f7 /numpy/lib/stride_tricks.py | |
parent | 09048a0e053e97078cad1d3070ff23580ef13562 (diff) | |
parent | fa9a74165479142e2c1671f871fe7c860146cd52 (diff) | |
download | numpy-e0b5e8740efe6d42c909c1374494e614592c65ab.tar.gz |
Merge pull request #9998 from mattip/nditer-as-context-manager
ENH: Nditer as context manager
Diffstat (limited to 'numpy/lib/stride_tricks.py')
-rw-r--r-- | numpy/lib/stride_tricks.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/numpy/lib/stride_tricks.py b/numpy/lib/stride_tricks.py index 6c240db7f..2abe5cdd1 100644 --- a/numpy/lib/stride_tricks.py +++ b/numpy/lib/stride_tricks.py @@ -123,9 +123,12 @@ def _broadcast_to(array, shape, subok, readonly): needs_writeable = not readonly and array.flags.writeable extras = ['reduce_ok'] if needs_writeable else [] op_flag = 'readwrite' if needs_writeable else 'readonly' - broadcast = np.nditer( + it = np.nditer( (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras, - op_flags=[op_flag], itershape=shape, order='C').itviews[0] + op_flags=[op_flag], itershape=shape, order='C') + with it: + # never really has writebackifcopy semantics + broadcast = it.itviews[0] result = _maybe_view_as_subclass(array, broadcast) if needs_writeable and not result.flags.writeable: result.flags.writeable = True |