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?

1
  • 3
    When I run that code, b is also non-writable, and the comparison works as expected. You could always try np.equal. Commented Jun 25, 2012 at 9:57

1 Answer 1

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?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.