1 多维数组的切片用法
c = np.array([[[0,1,2],[4,5,6],[8,7,5],[10,11,12]],[[6,2,3],[9,8,34],[100,101,102],[110,111,112]]]) c array([[[ 0, 1, 2], [ 4, 5, 6], [ 8, 7, 5], [ 10, 11, 12]], [[ 6, 2, 3], [ 9, 8, 34], [100, 101, 102], [110, 111, 112]]]) # c的shape是2 4 3 2指的是从最外面的括号向下一级括号看,下一级括号有两个,所以是2, # 3指的是从最后一级括号向内看,维数为3,所以是3 c.shape (2, 4, 3) # 这里的:即把shape[0]和shape[1]都包含了 c[:,1] array([[ 4, 5, 6], [ 9, 8, 34]]) c[1,:] array([[ 6, 2, 3], [ 9, 8, 34], [100, 101, 102], [110, 111, 112]]) c[0:2,1:2,2:3] array([[[ 6]], [[34]]]) a[::-1] # 逆序输出View Code