diff options
author | Stephan Hoyer <shoyer@gmail.com> | 2015-10-24 12:01:16 -0700 |
---|---|---|
committer | Stephan Hoyer <shoyer@gmail.com> | 2015-10-24 12:13:04 -0700 |
commit | 9fa0dba63ac76a43a157e07c2a43f4678355653e (patch) | |
tree | c9235cac6ead75cd7d13a21c3c01afd36dedd051 /numpy/lib/stride_tricks.py | |
parent | bf28b4432183126c21f0fa80852c335e9c1ed7c1 (diff) | |
download | numpy-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.py | 9 |
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 |