Does assignment with advanced indexing copy array data?
问题 I am slowly trying to understand the difference between view s and copy s in numpy, as well as mutable vs. immutable types. If I access part of an array with 'advanced indexing' it is supposed to return a copy. This seems to be true: In [1]: import numpy as np In [2]: a = np.zeros((3,3)) In [3]: b = np.array(np.identity(3), dtype=bool) In [4]: c = a[b] In [5]: c[:] = 9 In [6]: a Out[6]: array([[ 0., 0., 0.], [ 0., 0., 0.], [ 0., 0., 0.]]) Since c is just a copy, it does not share data and