在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/數(shù)據(jù)分析&挖掘  Python/ python3 二維數(shù)組的切片

python3 二維數(shù)組的切片

dims = np.array([[1, 2, 3, 4],[5, 6, 7, 8]])
c = 2
result = dims[c/2::1, c/2::1]

這個在python2.7.10上運(yùn)行無問題,但在python3.6.2上報(bào)錯

TypeError: slice indices must be integers or None or have an __index__ method
回答
編輯回答
負(fù)我心

result = dims[c//2::1, c//2::1]
python3 中 //是整除
例如 2/1 #2.0, 2//1 #2

2018年9月23日 11:55