我被告知在numpy中屏蔽将生成一个新副本。但是如何解释呢?
a [2]和b [0]在同一个内存块上,但可以保存不同的值。
import numpy as np
a = np.random.randint(0,20,5) # a = array([2, 1, 13, 12, 0])
b = a[a > 10] # b = array([13, 12])
a[2].__array_interface__['data'][0] == b[0].__array_interface__['data'][0] # true
b[0] = 20 # b = array([20, 12])
a # a = array([2, 1, 13, 12, 0])
a[2].__array_interface__['data'][0] == b[0].__array_interface__['data'][0] # true