我的問題是關於numpy中的數組切片。以下行爲的邏輯是什麼?numpy數組切片,爲什麼有時是二維數組,有時是一維數組
x = arange(25)
x.shape = (5, 5)
# This results in a 2-d array in which rows and columns are excerpted from x
y = x[0:2, 0:2]
# But this results in a 1-d array
y2 = x[0:2, 0]
我本來期望Y2是一個2-d數組,它包含行0和1的值,列0
這是超級方便有像切片'y2'是一維數組,例如,如果你想拉出一個陣列的每一列繪製它或者通過額外的信號處理運行它,等。 – tacaswell