Skip to content

Commit 50805f5

Browse files
committed
strided_scalar to return read-only array
1 parent e2873a0 commit 50805f5

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

nibabel/fileslice.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,12 @@ def strided_scalar(shape, scalar=0.):
767767
strided_arr : array
768768
Array of shape `shape` for which all values == `scalar`, built by
769769
setting all strides of `strided_arr` to 0, so the scalar is broadcast
770-
out to the full array `shape`.
770+
out to the full array `shape`. `strided_arr` is flagged as not
771+
`writeable`.
771772
"""
772773
shape = tuple(shape)
773774
scalar = np.array(scalar)
774775
strides = [0] * len(shape)
775-
return np.lib.stride_tricks.as_strided(scalar, shape, strides)
776+
strided_scalar = np.lib.stride_tricks.as_strided(scalar, shape, strides)
777+
strided_scalar.flags.writeable = False
778+
return strided_scalar

0 commit comments

Comments
 (0)