import numpy a=numpy.arange(12).reshape(3,4) b=a[:2,:2] #對子陣列b中值進行修改,將會影響到a陣列中的值 b[0][1]=1000 print(a) [[ 0 1000 2 3] [ 4 5 6 7] [ 8 9 10 11]] print(b) [[ 0 1000] [ 4 5]] #可以使用numpy中的copy方法,將和原陣列脫離關系 c=numpy.copy(a[:2,:2]) print(c) [[ 0 1000] [ 4 5]] c[1][1]=120 print(c) [[ 0 1000] [ 4 120]] print(a) [[ 0 1000 2 3] [ 4 5 6 7] [ 8 9 10 11]]
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/125467.html
標籤:Python
上一篇:二維陣列的切片和索引
