1

My question is an extension of that one: Immutable numpy array?

This code prints False, because even though a is immutable, b is not.

a = np.arange(10)
a.setflags(write=False)
b = a[1:]
b[1] = -1
print a == np.arange(10)

Which defeats the purpose of having readonly arrays in the first place. Is there a way to inherit readonlibility in numpy?

Community
  • 1
  • 1
cpa
  • 3,742
  • 4
  • 16
  • 22

1 Answers1

6

I get:

>>> b[1] = -1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: array is not writeable

This is with numpy 1.6.0 (on Python 2.6.2). Possibly this was a bug that was fixed, or a regression - what version of numpy are you using?

ecatmur
  • 152,476
  • 27
  • 293
  • 366