a = np.arange(24).reshape(2,3,4)
a
"""
array([[[ 0, 1, 2, 3],
[ 4, 5, 6, 7],
[ 8, 9, 10, 11]],
[[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]]])
"""
[a>13]
"""
[array([[[False, False, False, False],
[False, False, False, False],
[False, False, False, False]],
[[False, False, True, True],
[ True, True, True, True],
[ True, True, True, True]]])]
"""
# 單個條件時,返回一維數組,而非原來的shape
a[a>13]
# 兩個條件時
a[(a>15)&(a<20)]
############ 輸出內容 ###########
array([14, 15, 16, 17, 18, 19, 20, 21, 22, 23])
array([16, 17, 18, 19])
需要提醒的是,如果僅限於條件判斷,會返回原來相同shape的矩陣;而如果條件判斷的shape矩陣作爲索引的方式,則僅會返回一個一維數組。