In numpy subarrays obtained through any of slicing, masking or fancy indexing operations are just views to the original array, which can be demonstrated as follows:
$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy as np
>>> np.__version__
'1.11.0'
>>> a = np.arange(3); a[:2] = 111; a
array([111, 111, 2])
>>> a = np.arange(3); a[a<2] = 111; a
array([111, 111, 2])
>>> a = np.arange(3); a[[0,1]] = 111; a
array([111, 111, 2])
In the above example, the entire subarray was assigned to. However if we assign to an element of the subarray, the result of the slicing operation still behaves as a view, whereas the results of the masking and fancy indexing operations behave as independent copies:
>>> a = np.arange(3); a[:2][0] = 111; a
array([111, 1, 2])
>>> a = np.arange(3); a[a<2][0] = 111; a
array([0, 1, 2])
>>> a = np.arange(3); a[[0,1]][0] = 111; a
array([0, 1, 2])
Is this a bug in numpy, or is it by design? If it is by design, then what's the substantiation for such an inconsistency?