In [1]:
import numpy as np

In [2]:
a = np.arange(3)

In [3]:
print(a)


[0 1 2]

In [4]:
print(a.flags)


  C_CONTIGUOUS : True
  F_CONTIGUOUS : True
  OWNDATA : True
  WRITEABLE : True
  ALIGNED : True
  WRITEBACKIFCOPY : False
  UPDATEIFCOPY : False

In [5]:
print(type(a.flags))


<class 'numpy.flagsobj'>

In [6]:
print(a.flags.writeable)


True

In [7]:
print(a.flags['WRITEABLE'])


True

In [8]:
a[0] = 100

In [9]:
print(a)


[100   1   2]

In [10]:
a.flags.writeable = False

In [11]:
# a[0] = 0
# ValueError: assignment destination is read-only

In [12]:
a.flags['WRITEABLE'] = False
a.setflags(write=False)

In [13]:
a = np.arange(3)

In [14]:
print(a)


[0 1 2]

In [15]:
a.flags.writeable = False

In [16]:
a_view = a[1:]

In [17]:
print(a_view)


[1 2]

In [18]:
print(a_view.flags.writeable)


False

In [19]:
# a_view[0] = 100
# ValueError: assignment destination is read-only

In [20]:
# a_view.flags.writeable = True
# ValueError: cannot set WRITEABLE flag to True of this array

In [21]:
a.flags.writeable = True

In [22]:
print(a_view.flags.writeable)


False

In [23]:
a_view.flags.writeable = True

In [24]:
a_view[0] = 100

In [25]:
print(a_view)


[100   2]

In [26]:
print(a)


[  0 100   2]

In [27]:
a_view.flags.writeable = False

In [28]:
# a_view[1] = 1
# ValueError: assignment destination is read-only

In [29]:
print(a.flags.writeable)


True

In [30]:
a[1] = 1

In [31]:
print(a)


[0 1 2]

In [32]:
print(a_view)


[1 2]

In [33]:
a.flags.writeable = False

In [34]:
a_copy = a[1:].copy()

In [35]:
print(a_copy)


[1 2]

In [36]:
print(a_copy.flags.writeable)


True

In [37]:
a_copy[0] = 100

In [38]:
print(a_copy)


[100   2]

In [39]:
print(a)


[0 1 2]