n面元矩阵中的矩阵切片问题

时间:2019-06-02 16:43:54

标签: python

我被困在python函数中,但后来解决了。我对python n维表示法有疑问。该矩阵为A(2,4,4,3)。那么以A [:] [0:3,0:3,3]和A [:] [0:3,0:3] [3]的形式访问矩阵有何区别?

1 个答案:

答案 0 :(得分:0)

测试数组(2,4,4,3):

[[[[ 0  1  2]   [[[48 49 50]
   [ 3  4  5]     [51 52 53]
   [ 6  7  8]     [54 55 56]
   [ 9 10 11]]    [57 58 59]]

  [[12 13 14]    [[60 61 62]
   [15 16 17]     [63 64 65]
   [18 19 20]     [66 67 68]
   [21 22 23]]    [69 70 71]]

  [[24 25 26]    [[72 73 74]
   [27 28 29]     [75 76 77]
   [30 31 32]     [78 79 80]
   [33 34 35]]    [81 82 83]]

  [[36 37 38]    [[84 85 86]
   [39 40 41]     [87 88 89]
   [42 43 44]     [90 91 92]
   [45 46 47]]]   [93 94 95]]]

使用data [0:4,0:4,1]从4x4数组中获取第二个元素:

[[[ 3  4  5]   [[51 52 53]
  [15 16 17]    [63 64 65]
  [27 28 29]    [75 76 77]
  [39 40 41]]   [87 88 89]]]

另一方面,使用data [0:4,0:4] [1],您将获得4x4x2数组的第二部分:

[[[48 49 50]
  [51 52 53]
  [54 55 56]
  [57 58 59]]

 [[60 61 62]
  [63 64 65]
  [66 67 68]
  [69 70 71]]

 [[72 73 74]
  [75 76 77]
  [78 79 80]
  [81 82 83]]

 [[84 85 86]
  [87 88 89]
  [90 91 92]
  [93 94 95]]]