summaryrefslogtreecommitdiff
path: root/numpy/lib/stride_tricks.py
diff options
context:
space:
mode:
authormattip <matti.picus@gmail.com>2018-04-20 10:33:41 +0300
committermattip <matti.picus@gmail.com>2018-04-20 10:33:41 +0300
commit894dcab37ea2df285c6f48eb9b019a528b803cb5 (patch)
treea3b9dc69722329344fb7e9e8567c00f4cb2728e0 /numpy/lib/stride_tricks.py
parent23bc50db7b5d17758cb0a1ce82c3d2fc07164306 (diff)
downloadnumpy-894dcab37ea2df285c6f48eb9b019a528b803cb5.tar.gz
ENH: add NpyIter_Close, nditer__{enter,exit}__
Diffstat (limited to 'numpy/lib/stride_tricks.py')
-rw-r--r--numpy/lib/stride_tricks.py7
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