我剛剛偶然發現了一個我不太明白的numpy索引行爲。看起來numpy正在改變我的座標軸的順序,這取決於索引模式。不幸的是,我無法在文檔中找到對以下內容的解釋。有人可以向我解釋發生了什麼事嗎?Numpy索引重新排列數組
# This is expected: dimension 1 is reduced to length 1:
print np.ndarray(shape=(3,3,3,3))[:, [0], :, :].shape
>>> (3, 1, 3, 3)
# This is the unexpected behavior:
print np.ndarray(shape=(3,3,3,3))[:, [0], :, 0].shape
>>> (1, 3, 3)
我期望第二個命令產生(3,1,3)。如果我從第四個角度選擇一個元素,爲什麼前兩個維度的形狀會發生變化? 非常感謝!
編輯: 我見到這對numpy的1.11.0與蟒蛇2.7.11
儘管很晦澀,但這種行爲[記錄](http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#combining-advanced-and-basic-indexing)。 – 2016-06-21 09:37:26