[問題] 看不懂Python列表的語法意義[:, :, i]

作者: ruthertw (小葉老大)   2019-12-19 14:27:24
看到github上的教學範例:
...
if item > max_shelf:
max_shelf = item
b = BS[:, :, i]
else:
continue
...
請問這句
b = BS[:, :, i]
[:, :, i]
Python語法的意義是?
作者: dododavid006 (朔雪)   2019-12-19 14:47:00
: 在中括號中就是代表 slice ,當兩邊都沒有值時代表沒有起始與結束的值,通常是指整個範圍,而在中括號中用 , 則會把參數轉成 tuple 傳進去,相當於是傳(slice(None, None, None),slice(None,...), i)至於實際代表什麼意思就要看 BS 怎麼定義的了,一般應該是把某個維度的資料都拿出來
作者: justoncetime (台北叢林好冷~)   2019-12-19 19:25:00
要這樣問應該把原始連結附上,沒頭沒尾的要人怎麼看
作者: ruthertw (小葉老大)   2019-12-19 22:14:00
感謝dododavid006大大!

Links booklink

Contact Us: admin [ a t ] ucptt.com