In [1]:
import numpy as np
In [2]:
a = np.arange(3)
In [3]:
print(a)
In [4]:
print(a.flags)
In [5]:
print(type(a.flags))
In [6]:
print(a.flags.writeable)
In [7]:
print(a.flags['WRITEABLE'])
In [8]:
a[0] = 100
In [9]:
print(a)
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)
In [15]:
a.flags.writeable = False
In [16]:
a_view = a[1:]
In [17]:
print(a_view)
In [18]:
print(a_view.flags.writeable)
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)
In [23]:
a_view.flags.writeable = True
In [24]:
a_view[0] = 100
In [25]:
print(a_view)
In [26]:
print(a)
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)
In [30]:
a[1] = 1
In [31]:
print(a)
In [32]:
print(a_view)
In [33]:
a.flags.writeable = False
In [34]:
a_copy = a[1:].copy()
In [35]:
print(a_copy)
In [36]:
print(a_copy.flags.writeable)
In [37]:
a_copy[0] = 100
In [38]:
print(a_copy)
In [39]:
print(a)