我使用numpy模块创建了一个数组。我想切片该数组。当我想将“ slicing_array”上的内容更改为“ array”时。但是我发现了异常,但我不明白为什么会这样。我更改了“ slicing_array”,但没有影响“ array”。为什么会这样?
但是我发现了异常,但我不明白为什么会这样。我更改了“ slicing_array”,但没有影响“ array”。为什么会这样?
array=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
slicing_array = array[0:2,0:2] #slicing_array[0,1] currently value is 2
slicing_array[0,1]=slicing_array[0,1]*2 #slicing_array[0,1] currently value is 4
print(array[0,1]) #expected value is 4
#But when I change all "slicing_array", the "array" didn't change.
array=np.array([[1,2,3,4],[5,6,7,8],[9,10,11,12]])
slicing_array = array[0:2,0:2] #slicing_array[0,1] currently value is 2
slicing_array=slicing_array*2 #slicing_array[0,1] currently value is 4
print(array[0,1]) #expected value is 4, real value is 2