使用序列`:n`对3D矩阵进行块分割与指定列[[0,1]`不同

时间:2019-05-02 19:47:06

标签: python numpy python-3.6

谁能解释以下结果为何不同?在一种情况下,我指定了:2,该值应等效于[0,1],但出乎意料的是。

x = np.array([[[1,2,3],[4,5,6],[7,8,9]]])
array([[[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]]])

x.shape
(1, 3, 3)

# Works as expected
x[0, :, :2]
array([[1, 2],
       [4, 5],
       [7, 8]])

# Not as expected, the results got transposed
x[0, :, [0,1]]
array([[1, 4, 7],
       [2, 5, 8]])

0 个答案:

没有答案