summaryrefslogtreecommitdiff
path: root/numpy/lib/stride_tricks.py
diff options
context:
space:
mode:
authorStephan Hoyer <shoyer@gmail.com>2015-10-24 12:01:16 -0700
committerStephan Hoyer <shoyer@gmail.com>2015-10-24 12:13:04 -0700
commit9fa0dba63ac76a43a157e07c2a43f4678355653e (patch)
treec9235cac6ead75cd7d13a21c3c01afd36dedd051 /numpy/lib/stride_tricks.py
parentbf28b4432183126c21f0fa80852c335e9c1ed7c1 (diff)
downloadnumpy-9fa0dba63ac76a43a157e07c2a43f4678355653e.tar.gz
BUG: error in broadcast_arrays with as_strided array
Fixes GH6491
Diffstat (limited to 'numpy/lib/stride_tricks.py')
-rw-r--r--numpy/lib/stride_tricks.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/numpy/lib/stride_tricks.py b/numpy/lib/stride_tricks.py
index 416776ff4..f4b43a5a9 100644
--- a/numpy/lib/stride_tricks.py
+++ b/numpy/lib/stride_tricks.py
@@ -62,11 +62,14 @@ def _broadcast_to(array, shape, subok, readonly):
if any(size < 0 for size in shape):
raise ValueError('all elements of broadcast shape must be non-'
'negative')
+ 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(
- (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'],
- op_flags=['readonly'], itershape=shape, order='C').itviews[0]
+ (array,), flags=['multi_index', 'refs_ok', 'zerosize_ok'] + extras,
+ op_flags=[op_flag], itershape=shape, order='C').itviews[0]
result = _maybe_view_as_subclass(array, broadcast)
- if not readonly and array.flags.writeable:
+ if needs_writeable and not result.flags.writeable:
result.flags.writeable = True
return result